## trig

Apprentice
Posts: 11
Joined: 2011.02
Post: #1

This is done in 2d only.
So ultimately what I'm trying to achieve is...

(where remainder should be equal to the distance between m and p I believe)

...the only problem is that I can't figure out how to find n (or m for that matter).

p.s. my math is terrible.
Member
Posts: 54
Joined: 2010.10
Post: #2
Whoa, I'm struggling with this given your diagram looks 3D.

Assuming m,n,p an etc are all 2D vectors (they have an x and y component):

The length of the line between them is the sum of the componentwise differences, all squared, added up and then square rooted again.

ie:

diffx = p.x-n.x
diffy = p.y-n.y
length = sqrt(diffx*diffx + diffy*diffy)

Note that the multiplies effectively remove any minus signs so it doesn't matter which order you subtract - could be n minus p for the same answer.

I hope I haven't made a silly mistake there, I got up literally 20 seconds ago and am still waiting on the kettle for my first coffee...

Paul Johnson
Great Little War Game