
3D coordinates given angles and distance
Posted Tuesday, 24 May, 2011 - 14:44 by elaverick inThis isn't strictly an OpenTK question so I apologise for posting here but my lack of maths knowledge has tripped me up again.
I'm trying to extend my turtle drawing system into 3 dimensions, however I don't know how to calculate the resulting X,Y & Z co-ordinates given the appropriate rotations. I can manage it fine in 2D space but 3 dimensions is proving to be a bit beyond me.
2D version is as follows:
float cos = (float)Math.Cos(util.DegreeToRadian(turtleAngles.Z)); float sin = (float)Math.Sin(util.DegreeToRadian(turtleAngles.Z)); turtlePosition.X += cos * distance; turtlePosition.Y += sin * distance;


Comments
Re: 3D coordinates given angles and distance
I use this kind of method:
Re: 3D coordinates given angles and distance
It's basically the same, but the sin and cos affect the different coordinate pairs.
HOWEVER - it won't work the way you expect, in 3D the order of the rotations matters, i.e. if you rotate by X then Y then Z you end up with a completely different position than if you rotate by Z then Y then X. There are also issues with what are termed gimble locks using XYZ rotations in 3D, the existence of gimble locks is why a lot of 3D software uses quaternions, but they son't translate well to your application.
Before you do anything you need to pick a convention, what does the rotation actually mean, i.e. which axis is it rotating around. At that point you need to do the math to generate the axis and I'd personally just use GL.Rotate.