Esempio n. 1
0
        public Fixed2 Rotate(Fixed value)
        {
            Fixed tx, ty;

            tx = MathFixed.CosAngle(value) * x - y * MathFixed.SinAngle(value);
            ty = MathFixed.CosAngle(value) * y + x * MathFixed.SinAngle(value);
            return(new Fixed2(tx, ty));
        }
Esempio n. 2
0
        public Fixed2 Rotate(Fixed value)
        {
            Fixed tx, ty;

            tx = MathFixed.CosAngle(value) * x - y * MathFixed.SinAngle(value);
            ty = MathFixed.CosAngle(value) * y + x * MathFixed.SinAngle(value);
            // Debug.Log("f:" + f + "sin90" + Mathf.Sin(90) + "cos90" + (Math.Cos(90)));
            //1,0   tx=1*0-0  ty
            return(new Fixed2(tx, ty));
        }
Esempio n. 3
0
        public FixedNumber ToRotation()
        {
            if (x == 0 && y == 0)
            {
                return(new FixedNumber());
            }
            FixedNumber sin = this.normalized.y;

            if (this.x >= 0)
            {
                return(MathFixed.Asin(sin) / MathFixed.PI * 180);
            }
            else
            {
                return(MathFixed.Asin(-sin) / MathFixed.PI * 180 + 180);
            }
        }
Esempio n. 4
0
        public Fixed ToRotation()
        {
            if (x == 0 && y == 0)
            {
                return(new Fixed());
            }
            Fixed sin    = this.normalized.y;
            Fixed result = Fixed.Zero;

            if (this.x >= 0)
            {
                result = MathFixed.Asin(sin) / MathFixed.PI * 180;
            }
            else
            {
                result = MathFixed.Asin(-sin) / MathFixed.PI * 180 + 180;
            }
            // if(result==0){
            //     Debug.LogError("this.normalized "+this.normalized+" MathFixed.Asin(sin) "+MathFixed.Asin(sin));
            // }
            return(result);
        }
Esempio n. 5
0
        public static Fixed GetAsinTab(Fixed sin)
        {
            MathFixed math = Instance;

            //UnityEngine.Debug.Log("GetAsinTab");
            for (int i = _m_SinTab.Count - 1; i >= 0; i--)
            {
                if (sin > _m_SinTab[i])
                {
                    if (i == _m_SinTab.Count - 1)
                    {
                        return(new Fixed(i) / (tabCount / 4) * (PI / 2));
                    }
                    else
                    {
                        //return new Ratio(i);
                        return(Fixed.Lerp(new Fixed(i), new Fixed(i + 1), (sin - _m_SinTab[i]) / (_m_SinTab[i + 1] - _m_SinTab[i])) / (tabCount / 4) * (PI / 2));
                    }
                }
            }
            return(new Fixed());
        }
Esempio n. 6
0
        public static Fixed Sin(Fixed r)
        {
            MathFixed math = Instance;
            //int tabCount = SinTab.Count*4;
            Fixed result = new Fixed();

            r = (r * tabCount / 2 / PI);
            //int n = r.ToInt();
            while (r < 0)
            {
                r += tabCount;
            }
            while (r > tabCount)
            {
                r -= tabCount;
            }
            if (r >= 0 && r <= tabCount / 4)                // 0 ~ PI/2
            {
                result = GetSinTab(r);
            }
            else if (r > tabCount / 4 && r < tabCount / 2)       // PI/2 ~ PI
            {
                r     -= new Fixed(tabCount / 4);
                result = GetSinTab(new Fixed(tabCount / 4) - r);
            }
            else if (r >= tabCount / 2 && r < 3 * tabCount / 4)    // PI ~ 3/4*PI
            {
                r     -= new Fixed(tabCount / 2);
                result = -GetSinTab(r);
            }
            else if (r >= 3 * tabCount / 4 && r < tabCount)      // 3/4*PI ~ 2*PI
            {
                r      = new Fixed(tabCount) - r;
                result = -GetSinTab(r);
            }

            return(result);
        }
Esempio n. 7
0
 public static Fixed2 Parse(Fixed ratio)
 {
     return(new Fixed2(MathFixed.CosAngle(ratio), MathFixed.SinAngle(ratio)));
 }