How to get perpendicular vectors given a line segment [closed] - math

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How to get point A, B , C, and D?
if AB and CD are perpendicular to p0p1.
Assume p0A, p0B, p1C, and p1D have normalized length

The direction of the line is given by d = normalize(p1 - p0). To calculate a perpendicular vector we can use the cross product with (0, 0, 1). Which results in:
d_left = (-d.y, d.x)
d_right = (d.y, -d.x)
You haven't said how your coordinate system is aligned, so d_left might become d_right and vice versa.
You then get the desired points with:
A = p0 + d_left
B = p0 + d_right
C = p1 + d_left
D = p1 + d_right

Suppose rotate(p,d) is a operator to rotate p vector d angle.
Then if the inclination of p0p1 with positive x-axis is x. Then,
A = p0 + rotate(p1-p0,pi/2)/|p1-p0|
B = p0 + rotate(p1-p0,-pi/2)/|p1-p0|
C = p1 + rotate(p1-p0,pi/2)/|p1-p0|
D = p1 + rotate(p1-p0,-pi/2)/|p1-p0|

Related

Finding radius of ellipse at angle a? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I know the centre of an ellipse, x0 and y0. I know its width and height.
How do I get the radius at any given angle from x0/y0?
Its conventional to describe an ellipse, centred at x0,y0, whose axes of symmetry are aligned with the coordinate axes by the equation
(x-x0)*(x-x0)/(a*a) + (y-y0)*(y-y0)/(b*b) = 1
Here a and b are constants that define the size and shape of the ellipse.
To get the width we put y=y0, and then the x values are
x = x0 + a
x = x0 - a
so the width is
w = 2*a
Similarly the height is
h = 2*b
If we have a point x,y on the ellipse and the angle between the x-axis and the vector x0,y0 -> x,y is theta then x,y can be written
x = x0 + r*cos(theta)
y = x0 + r*sin(theta)
We need to find r so that x,y is on the ellipse. Plugging these values into the equation for the ellipse and simplifying:
r = 1.0/hypot( cos(theta)/a, sin(theta)/b)
I'm guessing that by radius you mean the distance between x,y and x0,y0. This is r above

Find all values of x,y that solve a*x + b*y = c [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 6 years ago.
Improve this question
I'm stuck in an exercise where I need to find all the values available to solve the equation
ax + by = c
Range: x >= -32768 , y <= 32767
Input: a,b,c.
Output: Values of x,y that solve the equation, otherwise zero.
I'm trying to create an algorithm which solves this, but no luck at the moment. Any help is highly appreciated.
there's 2 ways to solve this
first one:
iterate all (x) from -32768 to 32768
iterate all (y) from -32768 to 32768
check if a*x + b*y == c
which doesn't make that much sense, for y is dependant on x
a*x + b*y = c
b*y = c-a*x
y =(c-a*x)/b
so this algorithm is a lot faster:
iterate all (x) from -32768 to 32768
calculate y as (c-a*x)/b
check if a*x + b*y == c

Finding a Perpendicular vector with 2 cordinates already [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
i'm trying to practice my math for my upcoming exam, and i have an example that i'm trying to work out.
I'm trying to find an angle of exactly 90% (making vector B perpendicular to vector A)
A = (1, 3, 2)
B = (2, x, -2)
I've tried x = 0, x = 0.5, x = 1. I can't seem to get the Dot product to equal 0 (making them perpendicular of course).
Can anyone shed some light on how i can find "x" to make A and B 90 degree between each other?
Thanks!
This really should be on math.stackexchange, but someone else can move it. Just compute the dot product of the vectors:
(1, 3, 2) dot (2, x, -2) = 0
2 + 3x - 4 = 0
x = 2/3

Reverse mathematic equation [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Does anyone know how to reverse this equation when only Y, Z are known? I want to know what X is.
(X + Y) % 62 = Z
(X + Y) % 62 = Z
means that X+Y = 62*n + Z for arbitrary integer n, from that follows
X = 62*n+Z-Y
where n can be any integer value, if you need single solution you can pick arbitrary one or if you have any extra limitations on X value you'll need to find X that satisfies them
X = Z - Y + 62*n
where n is any integer.

How do I calculate the normal vector of a line segment? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed last year.
The community reviewed whether to reopen this question 3 months ago and left it closed:
Original close reason(s) were not resolved
Improve this question
Suppose I have a line segment going from (x1,y1) to (x2,y2). How do I calculate the normal vector perpendicular to the line?
I can find lots of stuff about doing this for planes in 3D, but no 2D stuff.
Please go easy on the maths (links to worked examples, diagrams or algorithms are welcome), I'm a programmer more than I'm a mathematician ;)
If we define dx = x2 - x1 and dy = y2 - y1, then the normals are (-dy, dx) and (dy, -dx).
Note that no division is required, and so you're not risking dividing by zero.
Another way to think of it is to calculate the unit vector for a given direction and then apply a 90 degree counterclockwise rotation to get the normal vector.
The matrix representation of the general 2D transformation looks like this:
x' = x cos(t) - y sin(t)
y' = x sin(t) + y cos(t)
where (x,y) are the components of the original vector and (x', y') are the transformed components.
If t = 90 degrees, then cos(90) = 0 and sin(90) = 1. Substituting and multiplying it out gives:
x' = -y
y' = +x
Same result as given earlier, but with a little more explanation as to where it comes from.
We know that: if two vectors are perpendicular, their dot product equals zero.
The normal vector (x',y') is perpendicular to the line connecting (x1,y1) and (x2,y2). This line has direction (x2-x1,y2-y1), or (dx,dy).
So,
(x',y').(dx,dy) = 0
x'.dx + y'.dy = 0
The are plenty of pairs (x',y') that satisfy the above equation. But the best pair that ALWAYS satisfies is either (dy,-dx) or (-dy,dx)
m1 = (y2 - y1) / (x2 - x1)
if perpendicular two lines:
m1*m2 = -1
then
m2 = -1 / m1 //if (m1 == 0, then your line should have an equation like x = b)
y = m2*x + b //b is offset of new perpendicular line..
b is something if you want to pass it from a point you defined

Resources