please refer to my quick diagram attached below.
what i’m trying to do is get the coordinates of the yellow dots by using the angle from the red dots’ known coordinates. assuming each yellow dot is about 20 pixels away from the x:50/y:250 red dot at a right angle (i think that’s what it’s called) how do i get their coordinates?
i believe this is very basic trigonometry and i should use Math.tan(), but they didn’t teach us much math in art school.
alt text http://www.freeimagehosting.net/uploads/e8c848a357.jpg
You don’t actually need trigs for this one. Simply use slopes, or change in
xandy.Given a line of slope
m = y/x, the line perpendicular to that line has slope-1/m, or-x/y.The slope m between the red dots is
-150/150, or-1/1. I noticed your positiveypoints down.Therefore, the positive slope is
1/1. Both of your x and y changes at the same speed, with the same amount.Once you know that, then it should be pretty easy to figure out the rest. Since they’re aligned at 45 degrees angle, the edge ratio of the
45-45-90triangle is1 : 1 : sqrt(2). So if your length is20, the individual x and y change would be20/sqrt(2), or roughly14in integers.So, your two yellow dots would be at
(36, 236), and(64, 264). If the lines are not aligned to a convenient degree, you would have to usearctan()or something similar, and get the angle between the line and the horizontal line, so you can figure out the ratio of x and y change.I hope my answer wasn’t too hard to follow. For a more general solution, see Troubadour’s answer.
Edit: Since the OP said the lower red dot is actually rotating around the upper red dot, we will need a more flexible solution instead.
I’m going to extend this answer from Troubadour’s, since I’m doing exactly the same thing. Please refer to his post as you read mine.
1.
Get the vector from origin (200, 100) to rotating point (50, 250):
2.
Rotate your vector by swapping the x and y, and negate x to get the new vector:
3.
Get the unit vector (of length 1) from the new vector:
4.
Get the displacement vector of length 20, by multiplying the unit vector.
5.
Add/Subtract this vector to/from your rotating vector (point):
I hope the above steps help you with formulating your code. Doesn’t matter what the angle it’s at, same steps.