# Floating Point Inaccuracies:

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

## Recommended Posts

I am currently working on a project and am rotating points through 3D space, I am using doubles to represent the actual points of the ships. However when I attempt to rotate a point (to bring the Frame of Reference to the ships heading- X-Y plane rotation) I get massive inaccuracies. cos sin 0 -sin cos 0 0 0 1 Currently I am using a 45 degree rotation (0.707 roughly) such that all things cancel out nicely and my point rotates (point is generated from the heading and elevation of the aircraft but not the bank which is taken into account by the transformation matrices). Running through I get a new X coord of 1 and a Y coord of -0.207 (Heading should be 0deg when converted to polar). However of course converting atan(-0.207/1) gives roughly -11 degrees... a massive inaccuracy. Is there any way to resolve this such that my transformations are accurate and correct? Thanks

##### Share on other sites
That big of an error can't be a floating point rounding etc. problem; show your code.

##### Share on other sites
Ditto what Zahlman said.
Also, (just checking) you do know that sin & cos etc take radians right?

##### Share on other sites
Yes I am aware that sin and cos take Radians (not that bad a noob :D)

//Code
FXdouble tempX = AC->ACXPos;
FXdouble tempY = AC->ACYPos;
FXdouble tempZ = AC->ACZPos;

AC->ACXPos = (ConversionMatrix->TL*tempX + ConversionMatrix->TM*tempY + ConversionMatrix->TR*tempZ);

AC->ACYPos = (ConversionMatrix->ML*tempX + ConversionMatrix->MM*tempY + ConversionMatrix->MR*tempZ);

AC->ACZPos = (ConversionMatrix->BL*tempX + ConversionMatrix->BM*tempY + ConversionMatrix->BR*tempZ);

FXdoubles are defined in the API I am using, its just a cross platform double thats correct across Windows/Linux/Unix and Solaris. ConversionMatrix is a struct of 9 doubles (TL->BR) arranged as X1 Y1 Z1

AC is the aircraft and contains all of the points related to it (Polar and Cartesian). The inputs to this function are guranteed to be in Radians (I have a function which converts between them and is correctly working in other sections of the code).

##### Share on other sites
Your matrix * vector multiplication code looks just fine so the problem must be with the code that generates the matrix values.

Can you show the code generating the matrix values, and perhaps post some example values of the matrix and the vector just before the rotation?

I don't suppose you're using Euler angles, and it's a composite rotation which of course wont always result in what you'd expect, if you're doing the rotations in the wrong order?

##### Share on other sites
No, just simple vector/matrix rotations...

Thanks

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 11
• 15
• 21
• 26
• 11