View Full Version : how do you calculate the distance?
erensaritas 10-16-2006, 07:11 PM hi there...
i found this to calculate the distance between two points at www.mathworld.com (http://www.mathworld.com)....
http://mathworld.wolfram.com/images/equations/Distance/equation1.gif
and then tried it on maxscript using as:
sqrt((2^($Box02.position.x - $Box01.position.x)) - (2^($Box02.position.y - $Box01.position.y)))
but the result is allways 0 :sad:
whats wrong? how do you calculate the distance?
thanks for help:thumbsup:
|
|
d3coy
10-16-2006, 07:17 PM
distance $box01.pos $box02.pos
:D
You've got the quares wrong - it is (B-A)^2, not 2^(B-A)...
Also, the example is for 2D distance only, you need the 3rd component, and you have to ADD all 3 squares before you calculate the Square root, not subtract them.
sqrt((($Box02.pos.x - $Box01.pos.x)^2) + (($Box02.pos.y - $Box01.pos.y)^2) + (($Box02.pos.z - $Box01.pos.z)^2) ) --full form
distance $Box01.pos $Box02.pos --as already mentioned
--when working with nodes, MXS is smart enough to know what you want - this is the short-hand form:
distance $Box01 $Box02
also you can make this even cleaner using a for loop. Well its just this:
http://mathworld.wolfram.com/images/equations/Distance/equation3.gif
r = 0
for i = 1 to 3 do
(
r = r + (abs(p0.transform.pos[i]-p1.transform.pos[i]))^2
)
sqrt(r)
This will use point2 values also if you set the 3 in the for loop to a 2.
erensaritas
10-17-2006, 07:23 AM
thank u so much friends:thumbsup:
distance is the easiest way of course but i didnt know:)
CGTalk Moderation
10-17-2006, 07:23 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.