|
JRSteensen Novice
Joined: 27 Jul 2004 Posts: 35
|
Posted: Mon Aug 17, 2020 6:32 pm
Need help calculating distance between 2 XYZ coordinates. |
Hey all. Been a long time since I did much scripting in CMUD, but getting back into it.
I am running the following and consistently getting a result of "0" regardless of input. I am guessing it has something to do with floating point math, but no matter where I put the %float() func, I'm not getting the desired output.
Code: |
;Formula for calculating distance between 2 XYZ Coordinates
;AB = sqrt((x2-x1)^2+(y2-y1)^2+(z2-z1)^2)
;%1 = X1, %2 = Y1, %3 = Z1, %4 = X2, %5 = Y2, %6 = Z2
$AB = %sqrt({((%4-%1)^2)-((%5-%2)^2)-((%6-%3)^2)})
#SAY $AB
|
I've tried everything from XYZDist 1 1 1 0 0 0 to XYZDist 999 999 999 0 0 0 for input. |
|
|
|
JRSteensen Novice
Joined: 27 Jul 2004 Posts: 35
|
Posted: Tue Aug 18, 2020 6:53 pm |
I got her solved! The below does famously.
Code: |
$AB = {%sqrt(((%4-%1)*(%4-%1))+((%5-%2)*(%5-%2))+((%6-%3)*(%6-%3)))}
#SHOW $AB
|
Is the ^x notation not supported by CMUD? I can't find ANYTHING about exponents in the documentation. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Tue Aug 18, 2020 8:52 pm |
I'm not sure why you have curly brackets in your %sqrt call
Try:
%sqrt(%float(((%4-%1)^2)-((%5-%2)^2)-((%6-%3)^2))) |
|
_________________ Discord: Shalimarwildcat |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Tue Aug 18, 2020 9:11 pm |
or
$x=(%4-%1)
$y=(%5-%2)
$z=(%6-%3)
$ab=%sqrt(%float(($x*$x)+($y*$y)+($z*$z)))
P.S. It is + not -, you had the formulae wrong. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
JRSteensen Novice
Joined: 27 Jul 2004 Posts: 35
|
Posted: Wed Aug 19, 2020 12:06 am |
shalimar wrote: |
or
$x=(%4-%1)
$y=(%5-%2)
$z=(%6-%3)
$ab=%sqrt(%float(($x*$x)+($y*$y)+($z*$z)))
P.S. It is + not -, you had the formulae wrong. |
Yeah I did. Thanks! |
|
|
|
|
|