Floating Point Precision Loss
Posted on
16th Feb 2014 07:03 pm by
admin
I'm writing a program to draw a three-dimensional cube (with a corner cut off) without using any 3D graphics APIs. The only API call I make is win32's SetPixel()
Everything is going great. I've drawn lines, faces, and even the entire cube. Then rotation came along.
For some reason, when I rotate my cube, it begins to shrink. I became confused, then I realised something. Floating point numbers are truncated.
Here's some code that is fired everytime the user presses 'X' on the keyboard.
Code:
p->setY( p->getY() * cos(5.0/180.0*PI) - p->getZ() * sin(5.0/180.0*PI));
p->setZ( p->getY() * sin(5.0/180.0*PI) + p->getZ() * cos(5.0/180.0*PI));
p is a Point object that I created. Here the Y value and the Z value of the Point are being set. The problem is everytime X is pressed, and this code is fired, a small amount of precision is lost. As a result, the cube shrinks.
I'm really completely stumped. I remember when studying assembler that floating point numbers can be truncated or rounded. I think rounding would solve my problem. Since 50% of the time the value would round up, and 50% of the time the value would round down.
Whereas with truncation values are always lost, and never gained.
No comments posted yet
Your Answer:
Login to answer
213
53
Other forums
php + mysql count consecutive data
I have a database of values and I want to work out how to display them if the values match a consecu
Variable passed to each() is not an array or object
Hi,
This is a email a friend type of form, and it isn't working anymore.
<?
add to sql result
ok see rite now my sites hit counter is counted from the mysql visitor log i need to clear it aft
Saving PHP output as a file
I wondered if anyone knows how to save the rendered output of a PHP script as a file?
I have
Set Categories
I am creating a submission form for somebody to come in and submit products. These products are sep
Optimize Code
Just started getting into the use of cookies. The following code will redirect users to a set URL s
Tracking Unique Clicks
Hi guys and gals,
Basically I have a database which tracks clicks on my outbound links, I do
Passing Arguments to execlp()
I'm writing a program that mimics a unix shell. It's supposed to take commands with arguments and ex
array_combine() error
getting an "Warning: array_combine() [function.array-combine]: Both parameters should have an e
need help to creat database
Hello Team, please guys i am stuck from three days with paypal issue for IPN but no luck yet now i w