CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2007
    Location
    Bangalore,India
    Posts
    164

    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. #2
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

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

    Quote Originally Posted by sujan.dasmahapatra View Post
    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. #3
    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. #4
    Join Date
    May 2009
    Posts
    2,413

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

    Quote Originally Posted by sujan.dasmahapatra View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured