1. #1
    Deleted

    Angle in Radians

    Hi,

    I was wondering if anyone had a formula to find the angle contained between the y-axis (the x axis would be fine too) and a set of coordinates in radians.

    e.g.
    x=276
    y=117

    I always hated trigonometry and cant seem to remember the formula's.

    A picture of what I mean:

  2. #2
    Its probably easier to find the angle in degrees and just convert it into radians. Your angle is arctan(y/x). Multiply that by 2pi/180 to find the measurement of the angle from the positive x axis. Then simply add pi/4 to find the angle from the negative y axis.

    edit: it sounds like you're asking for polar coordinates. Use the Pythagorean theorum to find the magnitude of the ray you're looking to measure. Your answer will be in the form (magnitude,direction)
    Last edited by rademach; 2011-08-28 at 12:02 AM.

  3. #3
    Herald of the Titans
    10+ Year Old Account
    Join Date
    Apr 2010
    Location
    Tempest Keep
    Posts
    2,810
    i thought 0 was on the right side, with π on the left instead of 0 on bottom

  4. #4
    That pic makes no sense......it should have

    0 radians on Right,
    pi/2 radians on top
    pi radians on left,
    3/2*pi on bottom

    Degree to radian,
    Angle/180 = x*pi

    ie, 90 degrees
    90/180 = 1/2 * pi

    Radian to degree
    x pi *180 = angle

    ie, 2 pi
    2 pi * 180 = 360 degree

    Edit: If you need to find the angle (x,y)
    Simply create a triangle with the x or y axis and use arctan to find the angle,

    ie,
    Tan (theta) = y/x

    arctan (theta) = arctan (y/x)
    Last edited by morbidjbyrd; 2011-08-28 at 12:14 AM.

  5. #5
    Herald of the Titans Maharishi's Avatar
    10+ Year Old Account
    Join Date
    May 2010
    Location
    Boston, Mass
    Posts
    2,923
    That graph is mind blowing, no one ever starts from the Y axis.

    There is no explicit formula, here's how you'd do it (note i didn't bother relabeling the axis, x is 0 pi yadayada):



  6. #6
    Deleted
    Haha seems I confused some people unintentionally. The reason I needed this was for:

    PlayerModel:SetRotation(rotationRadians)

    The problem with this was that 0 radians is straight down (or (0, -1)) which is why I was starting at the negative Y axis. It wasn't until I looked at Maharishi's diagram that I realized that I should be adding pi/4 to the radians rather than subtracting (the main reason I was so stumped and thought I was missing something really important in the 1st place).

    After sorting that it was easy, I just placed an offset if x < 0 (which btw I put as +pi/2 at first...damn brain farts)

    In case anyone needs this in the future here is how it looks:

    local radi = rad(atan(y/x)) + (3.14/2)

    if x < 1 then
    radi = radi + 3.14
    end

    Frame:SetRotation(radi)
    Thank you all for the help, it was very much appreciated.
    Last edited by mmoc3b93880aab; 2011-08-28 at 01:04 AM.

  7. #7
    Herald of the Titans Maharishi's Avatar
    10+ Year Old Account
    Join Date
    May 2010
    Location
    Boston, Mass
    Posts
    2,923
    Did you already build the code and have it work? As someone else mentioned, the graph is incorrect as 360 degrees is 2pi, not 1pi, so in your case the offset should be pi/2 not pi/4, right?

  8. #8
    Deleted
    Quote Originally Posted by Maharishi View Post
    Did you already build the code and have it work? As someone else mentioned, the graph is incorrect as 360 degrees is 2pi, not 1pi, so in your case the offset should be pi/2 not pi/4, right?
    Aha you are right, seems I fixed the "radi = radi + 3.14/2" part that I had in and forgot about everything else. I updated the code above.

  9. #9
    Herald of the Titans
    10+ Year Old Account
    Join Date
    Apr 2010
    Location
    Tempest Keep
    Posts
    2,810
    fixed graph angles on picture for you

Posting Permissions

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