Announcement

Collapse
No announcement yet.

Using Cosine and Sine

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Using Cosine and Sine

    hey guys,

    I need to use Cosine and Sine in Unreal Script, but I can't find the functions...are their functions if now how would I go about finding something...like coordinates of a point on a circle

    This is what I need to do:

    Code:
    X = radius * Cos(Angle)
    Y = radius * Sin(Angle)
    Thanks Jon

    #2
    how about

    local float angle;
    ...
    X = radius * Cos(Angle);
    Y = radius * Sin(Angle);
    ...
    .....

    Comment


      #3
      I find this website really helpful for looking up classes and functions

      http://wiki.beyondunreal.com/

      it also shows the hierarchy and everything.

      If you have Visual Studio or Visual Express, get nFringe... it also has a nice Class View and search tool (ctrl + shift + c) to find stuff. It integrates unrealscript into Visual Studio real nice to give you all the bells and whistles that come with Visual Studio, but for unrealscript (intellisense, get definition, etc etc). Though setting up a debug environment is a bit wonky at times... here's a tut for doing it:

      http://forecourse.com/2009/11/settin...for-epics-udk/

      Lastly cosine and sine are global functions defined in Object...

      http://wiki.beyondunreal.com/Legacy:Global_Function

      Object -> float cos( float A ) [static]

      Comment


        #4
        if you are using them for rotation, you need to multiply them by a specific number or the object will rotate extremely fast.

        example:
        Code:
        //rotates the roll variable evenly with the rotation of the floor normal
        pawn.roll = rotator(floor).yaw * cos(rotation.yaw * .000096);

        Comment


          #5
          This specific number is because as far as I know, all the cos, sin and tan functions use radians ... why by default most languages use.

          Comment


            #6
            Originally posted by KamiKaziKarl View Post
            if you are using them for rotation, you need to multiply them by a specific number or the object will rotate extremely fast.

            example:
            Code:
            //rotates the roll variable evenly with the rotation of the floor normal
            pawn.roll = rotator(floor).yaw * cos(rotation.yaw * .000096);

            Rotator.Yaw is stored as a RUU (Rotation Unreal Unit).

            There are three rotation units used in Unreal. Two of which are commonly used in real world, the third specialized for Unreal to keep efficiency and precission in the engine.

            An explanation of each.

            Degrees - degrees is what most 'human' described angles are described as. They are a modular loop of 0 -> 360. In very human scenarios this gives a nice 'whole value' level of precision relative to the human eye. The values though are extremely arbitrary... we only selected 360 due to ease of use of 360. Why? Because they can be broken in segments easily.

            halved - 180
            third - 120
            quartered - 90
            fifths - 72
            sixths - 60
            eighths - 45
            ninths - 40
            tenths - 36
            twelths - 30

            we get whole values very frequently. In old euclidian geometry this was VERY useful to deal with... especially considering that rational arithmetic (arithmetic of fractions) is a fairly 'new' principal of mathematics. Consider back in greek and roman times when the most advanced calculator was an abacus, and the number system was roman or greek numerals where there wasn't even a symbol for zero!


            Radians - radians are a more circular precise value. Angles are measures of circles, and the universal value that represents circles is PI. PI is the ratio of circumfrence to diameter. Now consider a circle of radius 1, it's diameter would be 2PI in length exactly. Now if we replace 360 degrees with 2PI we have a more mathematically accurate value (though not as human readable). This creates a lack of necessity for evenly divisible values. PI is inherently irrational, so we can just break the circle into segments rationally:

            halved - 180 - PI
            third - 120 - 2PI/3
            quartered - 90 - PI/2
            fifths - 72 - 2PI/5
            sixths - 60 - PI/3
            sevenths - 51.48... - 2PI/7
            eighths - 45 - PI/4
            ninths - 40 - 2PI/9
            tenths - 36 - PI/5
            elevenths - 32.7272... - 2PI/11
            twelths - 30 - PI/6

            When trig was put into action, angles were defined with this respect due to its mathematical accuracy. It also made a constant relation between the multiple uses of each trig function. The diameter, radius, circumfrence, and angle of curves have a constant relation of PI. So radians were implemented with purpose! Think of it the relationship there... a circle of radius 1 has an arclength or circumfrence of 2PI. If you have a semi-circle of radius one, the arclength of the semi-circle is the measured angle. You can then replace 1 with 'r' for arcs with radii longer then 1. And you get:

            arclength = 2*PI*measuredAngle

            this relationship does not exist in degrees. You can't say: 360*measuredAngle = arclength... because it doesn't... because 360 is NOT relative to anything. It's arbitrary!



            UnrealUnits - Unreal engine (and a lot of computer graphic engines) use relativistic values to represent angles. See in computers values can only be WHOLE values, there aren't fractions. You have to implicitly desribe fractional values.

            This is what a float is, or "Single-Precission floating point value"... a double is a "Double-precission floating point value", or a float with 64-bit bits of precission instead of 32. The "floating point" refers to the decimal point, it floats inside the binary representation of the number. The problem is it only allows for so much precission, float error occurs very frequently... I have an article on float error here:

            part 1 - http://www.lordofduct.com/blog/?p=90 <-define what a floating point value is
            part 2 - http://www.lordofduct.com/blog/?p=101 <-describe the errors related to floating point values
            These articles are long, I do suggest reading them though if you are confused why different numbers don't remain accurate when you are programming.

            we don't get a lot of accuracy with floats. That and the math is slower then integer math. But we have this integer with 4294967296 values of precission. That's why Unsigned-Integer (uint) has a range of 0-> 4294967295, and Integers (int) have a range of -2147483648 -> 2147483647. We also have any even more compact version of integer called a 'short' which is a 16-bit integer with a range of 65536. Unreal uses the 'short' for the compactness of it in memory (it takes up very little space on the stack).

            And the math of these values can be extremely fast! Now remember how we said the 360 degrees is a completely arbitrary value selected for the 'human' ease of use. Well... this is the same exact principal... just instead of 'human ease', it's 'binary computational ease'... we can add, divide, and subtract these values easily. And because short-integer's can't handle 'rational values', we have a precission range of 65536 to compensate. To the human eye you wouldn't even be able to see the numerous key points in these angles.





            NOw back at that equation shown in the commented text:

            cos(rotation.yaw * .000096);

            trig functions use radians for arithmetic precission with respect to constant relationship of PI with curves. But you took some RUU for YAW and scaled it by .000096. This results in some arbitrary value Theta... this theta though is marched into the scale of Radians which is modular around 0->2PI. This value can easily jump around inside this modular scale giving the illussion of moving swiftly... actually what is occuring is your jumping all over the place... it's similar to the principal of psuedo-random number generation... modulus is useful in that sake. You appear to be jumping around because your modular scale is in a weird spot... consider this code:

            http://code.google.com/p/lodgamebox/...impleRandom.as

            Code:
                            public function SimpleRandom( seed:int=-1, increment:int=0 )
                            {
                                    _mode = int.MAX_VALUE;
                                    _mult = 16807;//7^5
                                    _incr = increment;
                                    
                                    if(seed < 0)
                                    {
                                            var dt:Date = new Date();
                                            seed = dt.milliseconds;
                                    }
                                    
                                    _seed = seed % _mode;
                            }
                            
                            public function next():int
                            {
                                    _seed = (_mult * _seed + _incr) % _mode;
                                    return _seed;
                            }
            note the strong similarity of modular scale...? The result is a psuedo-ranom value that jumps around. You are essentially getting the same exact thing by placing RUU's into a trig function expecting radians.

            Comment


              #7
              good explanation, but I know you neglected to mention RUU is also used in quaternions in UDK, which just breaks each rotational axis into four sections. this is a complication i faced when i first started working with camera rotation.

              Comment


                #8
                actually I didn't fail to bring up quaternions because the subject was about unit scale, not about matrix containers (Vectors and Quaternions are special mathematical matrix types).

                Furthermore, Quaternion's don't use RUUs. They use standard quaternion scalar units (that need to be normalized on top of that). A properly normalized Quaternion has a 4 dimensional length of 1.

                RUU's can't be used in Quaternions because it defeats the relationship of the values with their implicit constants. That implicit constant being sqrt(-1) otherwise known as the imaginary number 'i'.

                Comment


                  #9
                  thanks for the clarification on that. It certainly helped clear up a few questions i had.

                  Comment

                  Working...
                  X