trig - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: trig (/thread-8633.html)
trig - tesil - Feb 12, 2011 07:24 PM
This is done in 2d only.
So ultimately what I'm trying to achieve is...
remainder = shadow_height - length(p,n);
(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.
RE: trig - Applewood - Feb 13, 2011 03:44 AM
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.
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...