Results 1 to 3 of 3

Math Help - Calculating Angle From Two Points in 3d Space

  1. #1
    Newbie
    Joined
    Apr 2008
    Posts
    2

    Calculating Angle From Two Points in 3d Space

    Hi Gurus,

    I am working in a 3d Application where i need to rotate a 3d Object as per Axis Selected (x,y,z). i have two point say (12,0,45) and (12,4,45) i.e i am towards Y Axis .

    I need to calculate an angle between this point and pass it to my selected Axis say X Axis in order to rotate my objects.


    pls Help me out.

    Thanks
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Member Henderson's Avatar
    Joined
    Dec 2007
    Posts
    127
    Thanks
    2
    Hopefully I'm understanding your problem.

    From what I'm reading, you want to rotate around an axis to translate a point in space to a new, projected point in space, and find the angle of revolution at the axis.

    There are a couple ways, but what I would do is this (using your example):

    -Rotating around the x-axis, we can ignore the variables in x (the 12s)
    -The cosine of the angle between two vectors is the dot product divided by their magnitudes, so
    \left(\begin{array}{cc}0\\45\end{array}\right) \cdot \left(\begin{array}{cc}4\\45\end{array}\right) = 2025


    To find the Magnitudes:
    \sqrt(0^2 +45^2) = 45, \sqrt(4^2 + 45^2) = \sqrt(2041)

    To find the angle:
    <br />
\cos(\Theta) = \frac{2025}{45\sqrt(2041)}
    <br />
\Theta \approx 5.08
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Apr 2008
    Posts
    2

    Unhappy

    Thanks,

    Code:
     Vector3 s = new Vector3(InputManager.startX, InputManager.startY, 
    InputManager.startZ);
    
    Vector3 e = new Vector3(InputManager.endX, InputManager.endY, InputManager.endZ);
               
              
     float t = InputManager.startY * InputManager.endY + InputManager.startZ * InputManager.endZ;
    
                 float sRoot = (float)Math.Sqrt((InputManager.startY * InputManager.startY) + (InputManager.startZ * InputManager.endZ));
                float eRoot = (InputManager.endY * InputManager.endY) + (InputManager.endZ * InputManager.endZ);
    
                float costheta = (float)((t) / Math.Sqrt(InputManager.endZ * eRoot));

    Output i am getting:

    Start : Vector3(1, 1, 1)
    End : Vector3(-87.91284, -54.91942, 142.8247)
    Cos Theata : 0.04806909
    Start : Vector3(1, 1, 1)
    End : Vector3(-88.92979, -52.88537, 141.8078)
    Cos Theata : 0.04933823
    Start : Vector3(1, 1, 1)
    End : Vector3(-89.94674, -50.85131, 140.7908)
    Cos Theata : 0.05063638
    Start : Vector3(1, 1, 1)
    End : Vector3(-89.94674, -50.85131, 140.7908)
    Cos Theata : 0.05063638
    Start : Vector3(1, 1, 1)
    End : Vector3(-90.96368, -48.81727, 139.7739)
    Cos Theata : 0.05196397
    Start : Vector3(1, 1, 1)
    End : Vector3(-90.96368, -48.81727, 139.7739)
    Cos Theata : 0.05196397
    Start : Vector3(1, 1, 1)
    End : Vector3(-91.98063, -46.78321, 138.7569)
    Cos Theata : 0.05332147

    oops i m not getting the right output........
    any Suggestion....
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Calculating an angle of a none right angle triangle
    Posted in the Trigonometry Forum
    Replies: 14
    Last Post: August 19th 2011, 02:42 PM
  2. Points on a circle, calculating angle
    Posted in the Geometry Forum
    Replies: 6
    Last Post: May 7th 2010, 01:51 PM
  3. Replies: 1
    Last Post: October 4th 2009, 07:45 AM
  4. Replies: 2
    Last Post: September 4th 2009, 11:19 PM
  5. calculating angle
    Posted in the Calculus Forum
    Replies: 6
    Last Post: August 15th 2007, 06:33 AM

Search Tags


/mathhelpforum @mathhelpforum