123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|524|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Cobra -> Circle / triangle maths

Sat, 23 Jan 2010, 20:52
HoboBen
Given the co-ordinates of two points, and an angle, I'm trying to find the third.

It's not working - can someone check my maths?

Perhaps I'm wrong to assume a right-angle in step 2?






Here's my implementation...



-=-=-
blog | work | code | more code
Sat, 23 Jan 2010, 21:08
Scherererer
Why not use polar coordinates?

assume the point A is the origin (so you may have to offset your values of x and y before and after the transformation).

Going to polar::
r = sqrt(x^2+y^2)
theta = arctan(y/x) ** you may have to use atan2 **

Coming back from polar::
x = r*cos(theta)
y = r*sin(theta)

so basically, convert it to polar, you'll get a value for r and theta for the point C with respect to the point A. Then add the angle A to theta, convert back to cartesian coordinates, and you've got the location for point B.

again, if A isn't located at the origin, then you'll need to offset the values (just do C.x -= A.x, C.y -= A.y) and then unoffset them when you convert back to cartesian (B.x + A.x, B.y += A.y)

-=-=-
YouTube Twitter
Computer Science Series: Logic (pt1) (part 2) (part 3) 2's Complement Mathematics: Basic Differential Calculus
Sat, 23 Jan 2010, 22:35
HoboBen
Thanks very much!

I had to read up a lot on polar coordinates, but it seems to have done the trick!




-=-=-
blog | work | code | more code