# Logo 3D

This topic is 4698 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm working on my current project called Logo 3D, which is a 3D version of Logo(that turtle). However, there is a problem about tracking the routine of the turtle. The following is a code segment of the 'forward function' in Logo 2D:
forward(int distance) {
//calculate the new position:
newX+=distance*Math.cos(Math.PI*theta/180.0);
newY+=distance*Math.sin(Math.PI*theta/180.0);

So what does the 3D one look like?

##### Share on other sites
You'll have to use spherical coordinates for that one...
They are 3 scalar coordinates; 'rho' is the distance from the origin, 'phi' is the longitude of the point in [0, 2pi] and 'theta' is the latitude angle in [-pi/2, pi/2]

To convert from spherical to cartesian and vice versa...
x = rho*cos(phi)*cos(theta)y = rho*sin(phi)*cos(theta)z = rho*sin(theta)----------------------------rho   = sqrt(x2 + y2 + z2)phi   = atan2(y,x)theta = atan2(z,sqrt(x2+y2))

edit:
If you can't use atan2, use any implementation of atan() that takes into account the quadrant in which the point lies. That means, don't use a version of atan() that returns results in the range [-pi/2, pi/2]. In that case, you'll have to calculate the angles as such: (at least the 'phi' one)
phi   = atan(y/x)theta = atan(z/sqrt(x2+y2))

##### Share on other sites
it works!
Thank you very much.

1. 1
Rutin
49
2. 2
3. 3
4. 4
5. 5

• 10
• 28
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633410
• Total Posts
3011727
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!