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?
Logo 3D
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:
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...
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)
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))
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement