Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
JRSteensen
Novice


Joined: 27 Jul 2004
Posts: 35

PostPosted: 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.
Reply with quote
JRSteensen
Novice


Joined: 27 Jul 2004
Posts: 35

PostPosted: 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.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4671
Location: Pensacola, FL, USA

PostPosted: 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
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4671
Location: Pensacola, FL, USA

PostPosted: 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
Reply with quote
JRSteensen
Novice


Joined: 27 Jul 2004
Posts: 35

PostPosted: 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!
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net