Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / The Sphere math

Author
Message
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 1st Mar 2008 17:53 Edited at: 2nd Mar 2008 01:07
Hey guys!

Latch solved the last circle math, but now I need a sphere math.

Like in the circle, you use r=sqrt(((x#-midx#)^2)+((z#-midz#)^2), which will return the radius from the center of the circle (midx#,midz#) to the position of the player (x#,z#). If you don`t get it this far, view this thread : Circle Math Problem

What I need now, is a formula which will return the radius from the center to any point in space.

Many thanks, TheComet

Oooooops!!! I accidentally formated drive c.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 1st Mar 2008 18:13
You are talking about a 3D sphere right? Because it's X,Y,Z position is the centre and you just use the standard 3D distance formula to do what you want.

TDK_Man

Yodaman Jer
User Banned
Posted: 1st Mar 2008 18:28
Ouch, I couldn't do those calculations even if my life depended on it...is this bad if I want to become a programmer? lol...


Thanks BigAdd!!
Tone3e
18
Years of Service
User Offline
Joined: 17th Feb 2007
Location: here
Posted: 1st Mar 2008 23:14
Well in some cases it is necessary, but I do not see why you could not learn it. That is just using the basic distance formula which is Square Root(a^2+b^2)

[center]
Come see the WIP!center]
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 2nd Mar 2008 01:07
Quote: "You are talking about a 3D sphere right? Because it's X,Y,Z position is the centre and you just use the standard 3D distance formula to do what you want.

TDK_Man"


I am talking about a 3d Sphere, but by doing the x,y,z position way, I don`t get the radius from the middle. And that is what I need.

TheComet

Oooooops!!! I accidentally formated drive c.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 2nd Mar 2008 03:13 Edited at: 2nd Mar 2008 03:16
TDK is right,

instead of just sqrt((x2-x1)^2+(z2-z1)^2), you'd have to add the y in there too: sqrt((x2-x1)^2+(y2-y1)^2+(z2-z1)^2)

Where x1,y1,z1 is the starting point and x2,y2,z2 is the ending point. Representing points in 3d space.

If you are talking about a sphere object that you want to find the radius of, just use
radius#=OBJECT SIZE(num)/2.0

Enjoy your day.
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 27th Mar 2008 00:39
Thanks guys! The "r=sqrt((x2-x1)^2+(y2-y1)^2+(z2-z1)^2)" worked fine!

Oooooops!!! I accidentally formated drive c.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 6th Apr 2008 21:10
I think he wanted to find the distance from the centre of the sphere to another object, that's why he didn't just use sphere position.
Is that right Comet?

Login to post a reply

Server time is: 2025-06-07 17:12:24
Your offset time is: 2025-06-07 17:12:24