Jump to content
  • Advertisement
Sign in to follow this  
Lord Darkblade

Floating Point Inaccuracies:

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

If you intended to correct an error in the post then please contact us.

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 this post


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

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!