I was playing with my JavaScript DHTML library - specifically the collision
detection. I had a function, getDistanceFrom(), that accepted another object
and returned the distance - in pixels as X and Y - between it and the
primary object.  But it didn't confer directionality.  For example a return
of "0,0" means that the corners of the objects were touching - but any of
the four corners - you don't know which direction the objects lie in.

So I wanted to add the ability to get direction... which meant a lot of math
I wasn't familiar with.  So I finally figured it out - this is the function
that (using the X,Y coordinates of the centers of the objects) determines
the direction and returns a degree value to the second decimal place (from
0.00 to 359.00):

Math.round( ( ( ( ( Math.atan2((TestX-ThisX),(ThisY-TestY)) ) * 180 /
Math.PI ) + 360 ) % 360 ) * 100) / 100;


So I made a frog!  Drag the little black dot (the fly) around and his eyes
will follow it.  The number in the frog is the bearing of the frog from the
fly:

http://www.depressedpress.com/Content/Development/JavaScript/Extensions/DP_P
anelManager/Example6.cfm

The actual library is here:

http://www.depressedpress.com/Content/Development/JavaScript/Extensions/DP_P
anelManager/Index.cfm

No... it's not really impressive, but it does represent a few hours of my
time.  ;^)

Jim Davis



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to 
date
Get the Free Trial
http://ad.doubleclick.net/clk;192386516;25150098;k

Archive: 
http://www.houseoffusion.com/groups/CF-Community/message.cfm/messageid:259547
Subscription: http://www.houseoffusion.com/groups/CF-Community/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.5

Reply via email to