Advertisement

I'm really bad at trig

Started by April 18, 2005 08:04 AM
10 comments, last by Alpha_ProgDes 19 years, 10 months ago
I'm trying to work out object placement and I'm having trouble because my trig is so bad. I need to find an end point in in 2D space considering I have the following information: A starting point, say x = y = 10.0f; An Angle between the start point and the end point, 0.0 to 359.999f The distance from the starting point to the end point, say 10.0f; How do I find the x and y coords of the end point? Thanks, and sorry about my lack of rudimentary maths skills.
Let's call the start point vector 'start', the angle 'alpha' and the distance 'd'. Then do the following:

1) Rotate start over alpha.
2) Normalize the result to have magnitude 1.0.
3) Multiply the result by d.
4) The resulting vector is the end vector.

(there's little trigonometry involved however)

Greetz,

Illco
Advertisement
Shall we start with point 1.

How do I rotate start over alpha?

1) Use Google and find:
x' = cos(alpha) * x - sin(alpha) * yy' = sin(alpha) * x + cos(alpha) * y


For the others points:
2) Normalize a vector:
magnitude = sqrt(x*x + y*y)x = x / magnitudey = y / magnitude


3) Multiply a vector by a scalar:
x = x * dy = y * d


I'd better not be doing your homework! If you look for stuff like this for yourself, it will stick at some point and improve your math skills.
How about :

1) knowing the length is 10.0f, create a vector (0.0f, 10.0f) and rotate it by the angle alpha
2) add the rotated vector to the original vector.
3) done

Saves doing normalisation etc. Picture it like starting with a vector up the Y axis of the length you want ie: 10.0f, and rotating it by alpha. That gives you the actual vector you need, it just needs translating by the original vector into position, which is like "starting it off" from the original vector position.

Remember the starting point is really just like a vector from the origin. So you can move the "tail" of the new vector to the "head" of the old one to give the end point.

I recommend drawing it down on graph paper, it simplifies it when you cansee it happening visually.

Hope that gives some furthur ideas :)
GCoder
x = x_start + cos( alpha ) * distance;
y = y_start + sin( alpha ) * distance;

You *really* should learn some math, becouse this is as basic as it gets.
You should never let your fears become the boundaries of your dreams.
Advertisement
@AP : No, it works for anything.
You should never let your fears become the boundaries of your dreams.
I guess I must be using the wrong angle then.
Try using angles in radians. Most math libraries implement all trigonometry using radians. Part one rotates the vector such that it points from the origin into the direction of the end point. Part two then adjusts the lenght such that it exactly indicates the end point.

Greetz,

Illco
is this a polar coordinate way to solve the problem?
i thought initially that you could use the dot product.

(i guess that's why i'm sticking with 2D)

Beginner in Game Development?  Read here. And read here.

 

This topic is closed to new replies.

Advertisement