I'm working with 3D geometry, and I've been at this for days. I'm beating my head against a wall, because I'm nearly done with the project. There's only one glitch in my system.(adsbygoogle = window.adsbygoogle || []).push({});

The Situation:

I have a 3D cartesian coordinate system with a Spherical system overlaid over it (the "poles" correspond with the Z axis, so that if you're looking from 90 degrees (polar north) you're looking down the Z axis.

I'm writing a computer program that does 3D geometric translations to "move" the points in the coordinate system.

The problem:

I have MOST of it working.

My only problem is when the user does a "translation" after a couple of rotations.

So basically,

Rotate the coordinate system by N degrees azimuth (at 0 degrees elevation)

Do an X, Y translation

Rotate the coordinate system back to the previous position

Now what was the translation in terms of X,Y,Z coordinates (at the new rotation)

Here's the program:

http://www.energematrice6.com/gview/index.html [Broken]

...In order to make it mess up, do the following.

Click at the top of the view area and drag to the bottom (rotate from 90 degrees elevation to 0)

Click and drag from right to left or left to right a couple of times. (rotates in azimuth)

Now right click and drag. (Yes I know the direction it moves is inverted so that you drag left it goes right you drag right it goes left). ...What it's NOT supposed to do is move closer and farther away.

In something resembling math language, here is the code I've been using:

TXtmp = Amount of X translation

TYtmp = Amount of Y translation

TZtmp = 0 (there is no Z translation)

Cos11 = Cosine of Azimuth Rotation

Sin11 = Sine of Azimuth Rotation

Cos12 = Cosine of Elevation Rotation

Sin12 = Sine of Elevation Rotation

TXtmp2 = TXtmp

TYtmp2 = TYtmp*Cos12 - TZtmp*Sin12

TZtmp2 = TYtmp*Sin12 + TZtmp*Cos12

Final X = TXtmp2*Cos11 - TYtmp2*Sin11

Final Y = TXtmp2*Sin11 + TYtmp2*Cos11

Final Z = TZtmp2

The raw code is below:

function galFEnd(){

TXtmp = Math.round(pointerX - pointerEndX)

TYtmp = Math.round(pointerY - pointerEndY)

TZtmp = 0

var Cos11 = -Math.cos(Cam1[1]*Math.PI/180)

var Sin11 = -Math.sin(Cam1[1]*Math.PI/180)

var TempAng = Cam[2]-Cam1[2]

var Cos12 = -Math.cos(TempAng*Math.PI/180)

var Sin12 = -Math.sin(TempAng*Math.PI/180)

TXtmp2 = TXtmp

TYtmp2 = TYtmp*Cos12 - TZtmp*Sin12

TZtmp2 = TYtmp*Sin12 + TZtmp*Cos12

TXtmp3 = TXtmp2*Cos11 - TYtmp2*Sin11

TYtmp3 = TXtmp2*Sin11 + TYtmp2*Cos11

TZtmp3 = TZtmp2

//Set the new focus position

Cam1[4] = Math.round((Cam1[4] + TXtmp3)/2)

Cam1[5] = Math.round((Cam1[5] + TYtmp3)/2)

Cam1[6] = Math.round((Cam1[6] + TZtmp3)/2)

}

Help would be appreciated. I'm getting terribly frustrated.

Thanks!

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Simple Geometry Question about a Complex Situation -Spherical/3D cartesian

Loading...

Similar Threads for Simple Geometry Question |
---|

A How to calculate the second fundamental form of a submanifold? |

I Diffeomorphism invariance and contracted Bianchi identity |

A Smoothness of multivariable function |

A Smooth extension on manifolds |

A Simple metric tensor question |

**Physics Forums | Science Articles, Homework Help, Discussion**