Results 1 to 3 of 3

Thread: Wrapping radians...

  1. #1

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Wrapping radians...

    how do you 'wrap' a large radians value so it falls within one revolution?

    If the input was larger than 2pi (a full revolution) then the answer would go back to 0. My inputs are single datatype and must maintain accuracy. I can't use Mod for this because that only works on integers.

    It must work with negative numbers too.

    My brain hurts.
    I don't live here any more.

  2. #2
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Wrapping radians...

    Maybe:

    If x is the angle, the same angle limited to one revolution would be

    x - 2*Pi*INT[x / (2*Pi)] for positive x.

    If x is negative, then first let y = 2*Pi - x and
    apply the above formula to y. Then change the sign of the result.

    I haven't checked it thoroughly though.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  3. #3

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Wrapping radians...

    Right. Well I have this...

    VB Code:
    1. Public Function RectifyRadians(ByVal rads As Single) As Single
    2.         'if makes sure the value is inside the range 0-2Pi (no negative angles or angles greater than 2 revolution)
    3.         '(2pi and zero are valid results)
    4.  
    5.         Dim temp As Single = rads / FULL_ROTATION
    6.         Return rads - (Int(temp) * FULL_ROTATION)
    7.  
    8.     End Function

    ...which works fine, BUT it uses the old legacy Int() function from VB6. I can't make it work otherwise. This is odd. I'll try to do it in VB.net instead...
    I don't live here any more.

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