CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: rotating a point by x-axis is the formula valid for any theta

1. Join Date
Sep 2007
Location
Bangalore,India
Posts
163

## rotating a point by x-axis is the formula valid for any theta

Dear Friends
I am trying to sweep a set of points by some degree theta. So I am using this formula
newx = x;
newy = y * cos(theta) - z * sin(theta);
newz = y * sin(theta) + z * cos(theta);

Is this formula valid for any degree theta.
Because when theta=360 degree, then sin(theta) = 1.47e--05

Is this okay. Please give me some idea.

2. Elite Member Power Poster
Join Date
Nov 2002
Location
California
Posts
4,556

## Re: rotating a point by x-axis is the formula valid for any theta

Originally Posted by sujan.dasmahapatra
Because when theta=360 degree, then sin(theta) = 1.47e--05
Floating point operations are never mathematically exact. You expected an answer of zero, but instead got 1.47e-05, which is probably within expected errors for floating point operations.

How close to zero do you need it to be?

3. Elite Member
Join Date
May 2009
Posts
2,413

## Re: rotating a point by x-axis is the formula valid for any theta

---
Last edited by nuzzle; October 5th, 2011 at 03:23 AM.

4. Elite Member
Join Date
May 2009
Posts
2,413

## Re: rotating a point by x-axis is the formula valid for any theta

Originally Posted by sujan.dasmahapatra
Is this okay. Please give me some idea.
You should get 0.0 for sin(2.0*PI).

Maybe you aren't specifying PI with enougth precision (digits). You can try this,

const double PI = 3.141592653589793238;

Also if you're using floats try double throughout. If you're using doubles already make sure you don't have a narrowing conversion to float somewhere.

Or maybe you simply are specifying theta in degrees while sin() expects radians.
Last edited by nuzzle; October 5th, 2011 at 03:27 AM.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•