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 Professional Discussion / Equation for a sphere? (Any maths geniuses out there? :))

Author
Message
Hamish McHaggis
23
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 7th Oct 2003 23:09
Gah! New smileys

Anyways, back on topic, I need the equation for a sphere in terms of the x, y and z angles of the sphere, I presume the equation will use trig so the radius can be 1.

Imagine 3 circles drawn along the x, y and z planes. Put a point at 1 along the x axis, rotate it around the y axis, then around the x axis, then the z axis. I'm sure this is easily done but I can't think for the life of me. Thanks.

Brains are for idiots.

Athelon XP 1400 Plus - Nvidia Geforce MX400 - 256mb RAM
heartbone
23
Years of Service
User Offline
Joined: 9th Nov 2002
Location:
Posted: 7th Oct 2003 23:22
A circle is described by a set of points (x,y) where
radius= Sqrt( x*x + y*y )


A sphere is described by a set of points (x,y,z) where
radius= Sqrt( x*x + y*y + z*z )

The more you see, the more you know.
The more you know, the more you see.
Hamish McHaggis
23
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 7th Oct 2003 23:34
Sorry, I am having trouble finding the points x, y and z. I need to find them from the 3 angles along the x, y and z axis'. So you have the coordinate (1,0,0), then rotate it around the y axis, then the x axis, then the z axis.

I have done this before, I am sure of it, just my brain isn't working at all. Thanks.

Brains are for idiots.

Athelon XP 1400 Plus - Nvidia Geforce MX400 - 256mb RAM
nuclear glory
22
Years of Service
User Offline
Joined: 2nd Oct 2003
Location:
Posted: 8th Oct 2003 00:05 Edited at: 8th Oct 2003 00:06
I believe I understand what you're saying. Basically, you have a sphere at position (0,0,0) and a point at the edge of the sphere (1,0,0). As the sphere rotates, this position stays at the edge of the sphere and follows rotation.

I see 2 ways of doing this properly. You could create an invisible object at position (0,0,0) and make the outside point a child of this, then rotate the parent.

Or... you could use a rotation matrix. Rotation in 3D graphics is usually handled this way as the math to accurately get a rotation position around a point is pretty intense.

What you do is define an indentity matrix. (Basically this is a null matrix or a matrix that is equal to 1, so when multipled by something it won't change the result) Then you combine the new rotations into the matrix. Then, you use this final matrix to transform your vector (1,0,0) and it gives you your new vector.

Care must be taken here though. As rotations are usually handled in a Vector4 format. (which is a 4 dimensional vector) So, you must have access to a command to translate this vector back into a vector3 format, otherwise your vector will come out screwy. The 3D Maths section may provide a way to do all of this.

Hope this helps. Sound like overkill? lol.
David T
Retired Moderator
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 8th Oct 2003 00:06
Oh I asked by maths teacher about this....

As well as using sin an cos, it has something to do with trig (as in triangles, I know sin + cos are trig ).

If I see him around I'll ask him he gave me the formula.

c:/dos
c:/dos run
run dos run
Hamish McHaggis
23
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 8th Oct 2003 00:09 Edited at: 8th Oct 2003 00:11
I kind of got it, although it still doesn't do exactely what I want, but thats not to do with rotation. Heres the code...



x1#,y1#, and z1# are the start coordinates and 4 are the result.

I dont want to use the DBPro commands, since this has to work in DBC too. Thanks for your help.

Brains are for idiots.

Athelon XP 1400 Plus - Nvidia Geforce MX400 - 256mb RAM
nuclear glory
22
Years of Service
User Offline
Joined: 2nd Oct 2003
Location:
Posted: 8th Oct 2003 00:12
Yeah, the internal matrix math runs of the sin/cos ops. But man, when I saw the stacks of sin/cos ops to figure out a rotation, my jaw about hit the floor.

As in 3D graphics, it's often used to update the vertex positions of an object as it's rotated. It can get ugly if done wrong. All the manual cos/sin ops I tried failed in one way or another, because when the rotation would hit 180 or 360, it would suddenly invert the values on one axis and send the point to the opposite side of the object on that axis.

Maybe you'll have better results
nuclear glory
22
Years of Service
User Offline
Joined: 2nd Oct 2003
Location:
Posted: 8th Oct 2003 00:17
Ok cool.

Yep, that looks similar to matrix math. Here I am telling you things you already know, lol.

I'm not entirely sure what the answer is though, sorry.
Hamish McHaggis
23
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 8th Oct 2003 00:26
Yeah, I don't really know it, as in I havent been taught it. I spent ages trying to figure it out a while ago and eventually figured it out myself. I am actually trying to find a point on the sphere based on 3 angles. The current code doesn't work it out when rotated along the x axis (because (1,0,0) is along the x axis ).

Brains are for idiots.

Athelon XP 1400 Plus - Nvidia Geforce MX400 - 256mb RAM
nuclear glory
22
Years of Service
User Offline
Joined: 2nd Oct 2003
Location:
Posted: 8th Oct 2003 00:32 Edited at: 8th Oct 2003 00:33
This would make a good DLL. As the DLL can access the DX7 matrix commands. I did it once as a test, it worked nicely. (for rotations)

Do you have the enhancement pack for the old DB?
I might be able to find the DLL someplace, lol.

I imagine this will work with DB as long as you send the real world X/Y/Z angles through. Want to give it a shot?

I'll send you the source if you have C++
Hamish McHaggis
23
Years of Service
User Offline
Joined: 13th Dec 2002
Location: Modgnik Detinu
Posted: 8th Oct 2003 00:46
Ummm, ok. Ive never used DLLs and I really wanted it for DBC because it needs to work for other people. But yeah, send it if you can .

Brains are for idiots.

Athelon XP 1400 Plus - Nvidia Geforce MX400 - 256mb RAM
nuclear glory
22
Years of Service
User Offline
Joined: 2nd Oct 2003
Location:
Posted: 8th Oct 2003 00:51
Ok cool. As long as they have the enhancement pack it should work.

I'm gonna test something I'm working on right quick. Then I'll go hunting for it, lol. I take it you have the MSN messenger? If so, I'll just hook up with you there. Probably within 15 minutes here.
Proteus 1935
22
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Brazil
Posted: 8th Oct 2003 01:23
If anyone cares:
http://mathworld.wolfram.com/Sphere.html
This is the best math/physics/chemistry site(s) i've ever found

Currently coding: 3d-2d latitude/longitude
Recent coding: elliptical orbits
Proteus
spooky
23
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 8th Oct 2003 01:43
I would just cheat:



If your mansion house needs haunting, just call Rentaghost!
nuclear glory
22
Years of Service
User Offline
Joined: 2nd Oct 2003
Location:
Posted: 8th Oct 2003 02:02
Good call.

I'm having trouble getting return values from the DLL.

Thanks Spooky

Login to post a reply

Server time is: 2026-07-25 07:01:15
Your offset time is: 2026-07-25 07:01:15