/// <param name="latitude">Latitude.</param>
        /// <param name="longitude">Longitude.</param>
        /// <param name="altitude">Altitude.</param>
        /// <param name="angleType">Angle type of latitude and longitude.</param>
        public Coordinates(double latitude, double longitude, double altitude = 0,
                           AngleType angleType = AngleType.Degrees)
        {
            if (angleType == AngleType.Radians)
            {
                latitude  *= Rad2Deg;
                longitude *= Rad2Deg;
            }

            latitude  = NormalizeDegrees(latitude);
            longitude = NormalizeDegrees(longitude);

            if (latitude > 90.0 || latitude < -90.0)
            {
                throw new ArgumentOutOfRangeException(nameof(latitude), "Argument must be in range of -90 to 90");
            }

            if (longitude > 180.0 || longitude < -180.0)
            {
                throw new ArgumentOutOfRangeException(nameof(longitude), "Argument must be in range of -180 to 180");
            }

            AngleType = angleType;
            Geo       = new GeoCoordinate(latitude, longitude, altitude);
        }
示例#2
0
        /// <summary>
        /// Initialize new instance of MathParser
        /// (Decimal Separator symbol is read from regional settings in system)
        /// </summary>
        public MathParser(AngleType AngleType = AngleType.Radians)
        {
            try { DecimalSeparator = Char.Parse(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator); }
            catch (FormatException) { DecimalSeparator = '.'; }

            this.AngleType = AngleType;
        }
示例#3
0
 /// <summary>
 /// コンストラクタ
 /// </summary>
 public AbstractPiece(int x, int y, AngleType angle)
     : base()
 {
     _position.X = x;
     _position.Y = y;
     UpdateAngle(angle);
 }
示例#4
0
 /// <summary>
 /// コンストラクタ
 /// </summary>
 public AbstractPiece(int x, int y, AngleType angle)
     : base()
 {
     _position.X = x;
     _position.Y = y;
     UpdateAngle(angle);
 }
示例#5
0
        public Angle(float value, AngleType angleType = AngleType.Degree)
        {
            switch (angleType)
            {
            case AngleType.Degree:
                _degrees = value < 0 ? value % 361 + 360 : value % 361;
                break;

            case AngleType.Gradian:
                value    = AngleHelper.GradianToDegree(value);
                _degrees = value < 0 ? value % 361 + 360 : value % 361;
                break;

            case AngleType.Radian:
                value    = AngleHelper.RadianToDegree(value);
                _degrees = value < 0 ? value % 361 + 360 : value % 361;
                break;

            case AngleType.Turn:
                value    = AngleHelper.TurnToDegree(value);
                _degrees = value < 0 ? value % 361 + 360 : value % 361;
                break;

            default:
                _degrees = 0f;
                break;
            }
        }
示例#6
0
        /// <summary>
        /// Генерує сітку
        /// </summary>
        public static List <double[]> generateGrid(
            double cellSize,
            out int outColumns,
            out int outRows,
            double coLatitudeBound  = 0,
            double coLatitudeBound2 = 180,
            double LongitudeBoundW  = 0,
            double LongitudeBoundE  = 360,
            AngleType resType       = AngleType.Radians
            )
        {
            if (coLatitudeBound > 90 || coLatitudeBound < 0)
            {
                throw new Exception("coLatitudeBound повинна бути: 0 <= coLatitude <= 90");
            }
            if (LongitudeBoundW >= 360 || LongitudeBoundW < 0 || LongitudeBoundE > 360 || LongitudeBoundE <= 0)
            {
                throw new Exception("LongitudeBounds must be 0<=LongitudeBound<360");
            }
            if (LongitudeBoundW > LongitudeBoundE)
            {
                throw new Exception("West longituge bound повинна бути менша за East longituge");
            }
            double gridRows = (180 - coLatitudeBound - (180 - coLatitudeBound2)) / cellSize;
            double gridColumns = (360 - LongitudeBoundW - (360 - LongitudeBoundE)) / cellSize;
            int    addRow = 0, addCol = 0;

            if ((Math.Round(gridRows) - gridRows) < 0)
            {
                addRow = 1;
            }
            if ((Math.Round(gridColumns) - gridColumns) < 0)
            {
                addCol = 1;
            }
            gridColumns = (int)gridColumns + addCol;
            outColumns  = (int)gridColumns;
            gridRows    = (int)gridRows + addRow;
            outRows     = (int)gridRows;
            int             gridCells       = (int)(gridColumns * gridRows);
            List <double[]> greed           = new List <double[]>(gridCells);
            double          coLatitudeStart = coLatitudeBound + (cellSize / 2D);
            double          LongStart       = deg2rad(LongitudeBoundW);

            #region ifRadians
            if (resType == AngleType.Radians)
            {
                MathFunc.deg2rad(ref cellSize);
                MathFunc.deg2rad(ref coLatitudeStart);
            }
            #endregion
            for (int r = 0; r < gridRows; r++)
            {
                for (int c = 0; c < gridColumns; c++)
                {
                    greed.Add(new double[] { coLatitudeStart + r * cellSize, LongStart + cellSize * (0.5 + c) });
                }
            }
            return(greed);
        }
        public AngleSelectorDisplay()
        {
            TypeToPushToInstance = AngleType.Radians;
            InitializeComponent();

            Line.DataContext = this;
        }
 /// <summary>
 /// Default constructor
 /// </summary>
 public PhysicalUnitTypeAttribute()
 {
     angleUnit  = AngleType.Radian;
     lengthUnit = LengthType.Meter;
     timeUnit   = TimeType.Second;
     massUnit   = MassType.Kilogram;
 }
示例#9
0
        public Angle(float value, AngleType angleType = AngleType.Radian)
        {
            Radians = 0f;
            switch (angleType)
            {
            default:
                throw new ArgumentOutOfRangeException(nameof(angleType), "Invalid AngleType.");

            case AngleType.Radian:
                Radians = value;
                break;

            case AngleType.Degree:
                Degrees = value;
                break;

            case AngleType.Gradian:
                Gradians = value;
                break;

            case AngleType.Revolution:
                Revolutions = value;
                break;
            }
        }
示例#10
0
        /// <summary>
        /// Constructor that enterprets angle argument based on supplied angleType. Relative angles not implemented
        /// </summary>
        public T_Angle(float angle, AngleType angleType)
        {
            switch (angleType)
            {
            case AngleType.AbsRad:
                AngAbsRad = angle;
                AngAbsDeg = (float)(AngAbsRad / (2 * Math.PI) * 360f);
                break;

            case AngleType.AbsDeg:
                AngAbsDeg = angle;
                AngAbsRad = (float)(AngAbsDeg / 360f * (2 * Math.PI));
                break;

            case AngleType.RelRad:
                throw new Exception("T_Angle: RelAbs not implemented. Does it even make sence?");
                break;

            case AngleType.RelDeg:
                throw new Exception("T_Angle: RelDeg not implemented. Does it even make sence?");
                break;

            default:
                break;
            }
        }
示例#11
0
        protected void CalculateAngle()
        {
            //Create line from the base of the whisker to the point on the whisker
            IWhiskerPoint baseWhiskerPoint = ControlPoints.Last();

            BasePoint = new Point(baseWhiskerPoint.XRatio * VideoWidth, baseWhiskerPoint.YRatio * VideoHeight);
            Point  anglePoint;
            Vector gradient;

            if (TValue == 1)
            {
                //If TValue == 1 (Point on whisker == base), calculate gradient at TValue = 1
                gradient      = GetBezierGradientVideoSize();
                gradient     *= -1;
                anglePoint    = BasePoint;
                anglePoint.X += gradient.X;
                anglePoint.Y += gradient.Y;
            }
            else
            {
                anglePoint = GetTValuePoint();
                gradient   = new Vector(anglePoint.X - BasePoint.X, anglePoint.Y - BasePoint.Y);
            }

            //Create line which will determine angle
            gradient.Normalize();
            TargetPoint = anglePoint;

            AngleLine = gradient;
            Angle     = AngleType.CalculateAngle(AngleLine);
        }
        public override void Reset()
        {
            textureInput  = null;
            textureOutput = null;

            angle = AngleType.Clockwise90;
        }
示例#13
0
 //constructor
 public AngleTagVertex(Point3d basePt, Line preline, Line postLine)
 {
     this.Pt        = basePt;
     this.ToPre     = preline;
     this.ToPost    = postLine;
     this.AngleType = VectorTools.CheckAngleType(PreVec, PostVec, 0.0005);
 }
示例#14
0
        private static void ToAngle(float angle, AngleType angType, int repeatTimes, int interval)
        {
            byte[] PanPositionByte = new byte[7];
            if (angType == AngleType.Hor)
            {
                PanPositionByte = new byte[] { 0xff, 0x01, 0x00, 0x4b, 0x00, 0x00, 0x00 };
            }
            else if (angType == AngleType.Ver)
            {
                PanPositionByte = new byte[] { 0xff, 0x01, 0x00, 0x4d, 0x00, 0x00, 0x00 };
            }
            var bt = BitConverter.GetBytes((ushort)(angle * 100));

            PanPositionByte[4] = bt[1];
            PanPositionByte[5] = bt[0];
            PanPositionByte[6] = (byte)(PanPositionByte[1] + PanPositionByte[2] + PanPositionByte[3] + PanPositionByte[4] + PanPositionByte[5]);
            for (int i = 0; i < repeatTimes; i++)
            {
                SerialPortCommunicate(PanPositionByte, null, panPort);
                Thread.Sleep(interval);
            }

            int iloop = 0;

            while (iloop < 200)
            {
                Thread.Sleep(100);
                if (IsInPosition(CurrentPosition(angType), angle))
                {
                    break;
                }
                iloop++;
            }
        }
示例#15
0
文件: Angle.cs 项目: oeoen/SharpDX
        /// <summary>
        /// Initializes a new instance of the SharpDX.AngleSingle structure with the
        /// given unit dependant angle and unit type.
        /// </summary>
        /// <param name="angle">A unit dependant measure of the angle.</param>
        /// <param name="type">The type of unit the angle argument is.</param>
        public AngleSingle(float angle, AngleType type)
        {
            radiansInt = 0;
            switch (type)
            {
            case AngleType.Revolution:
                radians = MathUtil.RevolutionsToRadians(angle);
                break;

            case AngleType.Degree:
                radians = MathUtil.DegreesToRadians(angle);
                break;

            case AngleType.Radian:
                radians = angle;
                break;

            case AngleType.Gradian:
                radians = MathUtil.GradiansToRadians(angle);
                break;

            default:
                radians = 0.0f;
                break;
            }
        }
示例#16
0
        public Angle(float value, AngleType angleType = AngleType.Radian)
        {
            switch (angleType)
            {
            default:
                Radians = 0f;
                break;

            case AngleType.Radian:
                Radians = value;
                break;

            case AngleType.Degree:
                Radians = value * _degreeRadian;
                break;

            case AngleType.Revolution:
                Radians = value * _tau;
                break;

            case AngleType.Gradian:
                Radians = value * _gradianRadian;
                break;
            }
        }
示例#17
0
        public void SpriteRotationConstructorTest1()
        {
            float          value           = 0F;              // TODO: Initialize to an appropriate value
            AngleType      measurementType = new AngleType(); // TODO: Initialize to an appropriate value
            SpriteRotation target          = new SpriteRotation(value, measurementType);

            Assert.Inconclusive("TODO: Implement code to verify target");
        }
示例#18
0
    // Use this for initialization
    void Start()
    {
        int cameraView = PlayerPrefs.GetInt(GameManager.CAMERA_VIEW, 0);

        angleType    = (cameraView == 1) ? AngleType._3D : AngleType._2D;
        rotateCamera = GetComponent <Camera>();
        LoadAngleType();
    }
示例#19
0
        public double AngleBetween(Vector v, AngleType angleType = AngleType.Radians)
        {
            double angleRads = Math.Acos(this.Dot(v) / (this.Abs() * v.Abs()));

            return(angleType == AngleType.Radians
                ? angleRads
                : angleRads * 180d / Math.PI);
        }
        public static IVertexSource Rotate(this IVertexSource source, double angle, AngleType angleType = AngleType.Radians)
        {
            if (angleType == AngleType.Degrees)
            {
                angle = MathHelper.DegreesToRadians(angle);
            }

            return(new VertexSourceApplyTransform(source, Affine.NewRotation(angle)));
        }
示例#21
0
 void FormatFixed()
 {
     #region AngleTypeDemo2_FormatFixed
     Debug.Log(AngleType.Format(1234.5678, format: "0.0000"));
     // Prints: "1234.5678°"
     Debug.Log(AngleType.Format(1234.5678, format: "0.00"));
     // Prints: "1234.57°"
     #endregion
 }
示例#22
0
        public float SlopeWChoice(AngleType ang)
        {
            float f = this.SlopeAngle;

            if (ang == AngleType.Degree)
            {
                f = f * 180F / (float)Math.PI;
            }
            return(f);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="angleType">Type of angle</param>
 /// <param name="lengthType">Type of length</param>
 /// <param name="timeType">Type of time</param>
 /// <param name="massType">Type of mass</param>
 public PhysicalUnitTypeAttribute(AngleType angleType   = AngleType.Radian,
                                  LengthType lengthType = LengthType.Meter,
                                  TimeType timeType     = TimeType.Second,
                                  MassType massType     = MassType.Kilogram)
 {
     this.angleUnit  = angleType;
     this.lengthUnit = lengthType;
     this.timeUnit   = timeType;
     this.massUnit   = massType;
 }
示例#24
0
 public void SetRotation(float angle, AngleType aType)
 {
     if (aType == AngleType.RADIANS)
     {
         Rotation = angle;
     }
     else
     {
         Rotation = angle * ((float)Math.PI / 180.0f);
     }
 }
示例#25
0
 /// <summary>
 /// Construit un angle avec la valeur passée en paramètre
 /// </summary>
 /// <param name="angle">Angle de départ</param>
 public AngleDelta(double angle, AngleType type = AngleType.Degre)
 {
     if (type == AngleType.Degre)
     {
         _angle = angle;
     }
     else
     {
         _angle = (180 * angle / Math.PI);
     }
 }
示例#26
0
        /// <summary>
        /// y = a*x + b
        /// </summary>
        public static void GetLineParameters(double x, double y, double angle, AngleType angleType, out double a, out double b)
        {
            a = Math.Tan
                (
                angleType == AngleType.Radians ?
                angle :
                DegreesToRadians(angle)
                );

            b = y - (a * x);
        }
示例#27
0
        public AngleSelectorDisplay()
        {
            TypeToPushToInstance = AngleType.Radians;

            InitializeComponent();

            Line.DataContext = this;

            mTextBoxLogic = new TextBoxDisplayLogic(this, this.TextBox);

            // do we have to refresh the context menu? We do in the TextBoxDisplay
        }
示例#28
0
 private static double fixAngle(double input, AngleType type)
 {
     if (type == AngleType.Degrees)
     {
         return(input % 360);
     }
     else if (type == AngleType.Radiant)
     {
         return(input % (2 * Math.PI));
     }
     return(input);
 }
示例#29
0
        public BaseBullet(Point startPos, AngleType angle, IPlane plane)
        {
            Parent   = plane;
            Position = startPos;
            Angle    = angle;
            switch (Angle)
            {
            case  AngleType.Zero:
                BulletImage = Resource.bul02;
                Position    = new Point {
                    X = Position.X, Y = Position.Y - 17
                };
                break;

            case  AngleType.Thirty:
                BulletImage = Resource.bul02_30;
                Position    = new Point {
                    X = Position.X + 12, Y = Position.Y - 12
                };
                break;

            case AngleType.Sixty:
                BulletImage = Resource.bul02_60;
                Position    = new Point {
                    X = Position.X + 2, Y = Position.Y - 17
                };
                break;

            case AngleType.OneTwoZero:
                BulletImage = Resource.bul02_120;
                Position    = new Point {
                    X = Position.X - 35, Y = Position.Y - 12
                };
                break;

            case AngleType.OneFiveZero:
                BulletImage = Resource.bul02_150;
                Position    = new Point {
                    X = Position.X - 20, Y = Position.Y - 12
                };
                break;

            default:
                break;
            }
            timer           = new Timer(50);
            timer.AutoReset = true;
            timer.Elapsed  += Timer_Elapsed;
            timer.Start();
            BoomHold = TimeSpan.FromSeconds(3);
            ID       = Guid.NewGuid().ToString();
        }
示例#30
0
 //------------------------------------------------------------------------------------------------
 public Angle(double val, AngleType type)
 {
     if (type == AngleType.Deg)
     {
         _deg = val;
         _rad = DegToRad(val);
     }
     else
     {
         _rad = val;
         _deg = RadToDeg(val);
     }
 }
 public void Add(float aValue, AngleType aType)
 {
     if (aType == AngleType.Radians)
     {
         _Radians += aValue;
         _Degrees  = RadToDeg(_Radians);
     }
     else if (aType == AngleType.Degrees)
     {
         _Degrees += aValue;
         _Radians  = DegToRad(_Degrees);
     }
 }
示例#32
0
        /// <summary>
        /// Compiles a string into a single variable executable function.
        /// </summary>
        /// <param name="function">A single variable function where 'x' is the variable.</param>
        /// <param name="angleType">The angle type used by trigonometric functions.</param>
        /// <param name="cultureInfo">
        /// Provide culture-specific formatting information. Default value is CultureInfo.CurrentCulture.
        /// </param>
        /// <returns>The executable function, or null if compilation failed.</returns>
        /// <example>
        /// <code>
        /// Func<double, double> sin = Compiler.CompileFunction("sin(x)");
        /// </code>
        /// </example>
        public static Func <double, double> CompileFunction(
            string function,
            AngleType angleType     = AngleType.Radian,
            CultureInfo cultureInfo = null)
        {
            CompileResult result = Compile(function, angleType, cultureInfo);

            if (result.IsSuccess)
            {
                return(result.Functions[0]);
            }

            return(null);
        }
        public double Invoke(double Arg, AngleType AngleType)
        {
            switch (AngleType)
            {
                case AngleType.Degrees:
                    return Invoke((Math.PI / 180) * Arg);

                case AngleType.Grades:
                    return Invoke((Math.PI / 200) * Arg);

                default:
                case AngleType.Radians:
                    return Invoke(Arg);
            }
        }
示例#34
0
 public override void UpdateAngle(AngleType angle)
 {
     switch (angle)
     {
         case AngleType.Angle0:
             Map = new int[,]
             {
                 { 0, 0, 0, 0 },
                 { 1, 1, 0, 0 },
                 { 0, 1, 1, 0 },
                 { 0, 0, 0, 0 }
             };
             break;
         case AngleType.Angle90:
             Map = new int[,]
             {
                 { 0, 0, 1, 0 },
                 { 0, 1, 1, 0 },
                 { 0, 1, 0, 0 },
                 { 0, 0, 0, 0 }
             };
             break;
         case AngleType.Angle180:
             Map = new int[,]
             {
                 { 0, 0, 0, 0 },
                 { 1, 1, 0, 0 },
                 { 0, 1, 1, 0 },
                 { 0, 0, 0, 0 }
             };
             break;
         case AngleType.Angle270:
             Map = new int[,]
             {
                 { 0, 0, 1, 0 },
                 { 0, 1, 1, 0 },
                 { 0, 1, 0, 0 },
                 { 0, 0, 0, 0 }
             };
             break;
     }
     SwapXY();
     Angle = angle;
 }
示例#35
0
 /// <summary>
 /// Initialize a new SpriteRotation with the specified value using the specified unit.
 /// </summary>
 /// <param name="value">The value to initialize this SpriteRotation to.</param>
 /// <param name="measurementType">The type of angle that value represents.</param>
 public SpriteRotation(float value, AngleType measurementType)
 {
     if (measurementType == AngleType.Radians)
     {
         _radians = value;
     }
     else if(measurementType == AngleType.Degrees)
     {
         _radians = MathHelper.ToRadians(value);
     }
     else if (measurementType == AngleType.Gradians)
     {
         _radians = MathHelper.ToRadians(value / .9f);
     }
     else
     {
         throw new NotImplementedException("The specified AngleType has not been implemented.");
     }
 }
示例#36
0
        /// <summary>
        /// Calculate expression in reverse-polish notation
        /// </summary>
        /// <param name="RPNExpression">Math expression in reverse-polish notation</param>
        /// <returns>Result</returns>
        public static double Evaluate(List<Token> RPNExpression, AngleType AngleType = AngleType.Radians)
        {
            var Stack = new Stack<double>(); // Contains operands

            // Analyse entire expression
            foreach (var Token in RPNExpression)
            {
                // if it's operand then just push it to stack
                if (Token is Constant)
                    Stack.Push((Constant)Token);

                else if (Token is Variable)
                    Stack.Push(((Variable)Token).Value);

                else if (Token is TrigonometricFunction)
                    Stack.Push((Token as TrigonometricFunction).Invoke(Stack.Pop(), AngleType));

                // Otherwise apply operator or function to elements in stack
                else if (Token is IEvaluatable)
                {
                    int Count = (Token as IEvaluatable).ParameterCount;

                    List<double> Arguments = new List<double>(Count);

                    for (int i = 0; i < Count; ++i)
                        Arguments.Add(Stack.Pop());

                    Arguments.Reverse();

                    Stack.Push((Token as IEvaluatable).Invoke(Arguments.ToArray()));
                }
            }

            // At end of analysis in stack should be only one operand (result)
            if (Stack.Count > 1) throw new ArgumentException("Excess operand");

            return Stack.Pop();
        }
示例#37
0
 public TrigLib(AngleType angleType)
 {
     selectedAngleType = angleType;
 }
示例#38
0
 public string ToString(AngleType type)
 {
     return type == AngleType.Degrees ? this.ToDegrees().Measure.ToString() : this.ToRadians().Measure.ToString();
 }
示例#39
0
 public Angle(double measure, AngleType type)
 {
     Measure = measure; Type = type;
 }
        public AngleSelectorDisplay()
        {

            TypeToPushToInstance = AngleType.Radians;
            InitializeComponent();

            Line.DataContext = this;
        }
示例#41
0
 public PieceZ(int x, int y, AngleType angle)
     : base(x, y, angle)
 {
 }
示例#42
0
 public void SpriteRotationConstructorTest1()
 {
     float value = 0F; // TODO: Initialize to an appropriate value
     AngleType measurementType = new AngleType(); // TODO: Initialize to an appropriate value
     SpriteRotation target = new SpriteRotation(value, measurementType);
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
示例#43
0
 /// <summary>
 /// Генерує сітку 
 /// </summary>
 public static List<double[]> generateGrid(
     double cellSize,
     out int outColumns,
     out int outRows,
     double coLatitudeBound = 0,
     double coLatitudeBound2 = 180,
     double LongitudeBoundW = 0,
     double LongitudeBoundE = 360,
     AngleType resType = AngleType.Radians
     )
 {
     if (coLatitudeBound > 90 || coLatitudeBound < 0) { throw new Exception("coLatitudeBound повинна бути: 0 <= coLatitude <= 90"); }
     if (LongitudeBoundW >= 360 || LongitudeBoundW < 0 || LongitudeBoundE > 360 || LongitudeBoundE <= 0) { throw new Exception                           ("LongitudeBounds must be 0<=LongitudeBound<360"); }
     if (LongitudeBoundW > LongitudeBoundE) { throw new Exception("West longituge bound повинна бути менша за East longituge"); }
     double gridRows = (180 - coLatitudeBound- (180 - coLatitudeBound2)) / cellSize;
     double gridColumns = (360 - LongitudeBoundW - (360 - LongitudeBoundE)) / cellSize;
     int addRow = 0, addCol = 0;
     if ((Math.Round(gridRows) - gridRows) < 0) { addRow = 1; }
     if ((Math.Round(gridColumns) - gridColumns) < 0) { addCol = 1; }
     gridColumns = (int)gridColumns + addCol;
     outColumns = (int)gridColumns;
     gridRows = (int)gridRows + addRow;
     outRows = (int)gridRows;
     int gridCells = (int)(gridColumns * gridRows);
     List<double[]> greed = new List<double[]>(gridCells);
     double coLatitudeStart = coLatitudeBound + (cellSize / 2D);
     double LongStart = deg2rad(LongitudeBoundW);
     #region ifRadians
     if (resType == AngleType.Radians)
     {
         MathFunc.deg2rad(ref cellSize);
         MathFunc.deg2rad(ref coLatitudeStart);
     }
     #endregion
     for (int r = 0; r < gridRows; r++)
     {
         for (int c = 0; c < gridColumns; c++)
         {
             greed.Add(new double[] { coLatitudeStart + r * cellSize, LongStart+cellSize * (0.5 + c)});
         }
     }
     return greed;
 }
示例#44
0
 /// <summary>
 /// 角度更新
 /// </summary>
 /// <param name="angle"></param>
 public abstract void UpdateAngle(AngleType angle);
示例#45
0
    // calcul des donnees : angle, bissectrice, normales en fonction de sa position et de la position des points voisins
    public virtual void Update(bool recursive=true)
    {
        if (_prevEdge != null && _nextEdge != null)
        {
            _prevEdge.Update ();
            _nextEdge.Update ();

            Vector2 prevNormal = _prevEdge.GetNormal ();
            Vector2 nextNormal = _nextEdge.GetNormal ();
            Vector2 nextEdgeDirection = _nextEdge.ToVector2 ();

            _normal = (prevNormal + nextNormal).normalized;
            _angle = 180 - Vector2.Angle (prevNormal, nextNormal);

            Vector2 prevDirection = _prevEdge.ToVector2 ().normalized * -1;
            Vector2 nextDirection = _nextEdge.ToVector2 ().normalized;
            Vector2 abp = (Vector2)this + (prevDirection + nextDirection);
            _angularBisector = StraightLine.From2Point (this, abp);

            float prevNormalNextEdgeDot = Vector2.Dot (prevNormal, nextEdgeDirection);

            if (Utils.Approximately (prevNormalNextEdgeDot, 0))
            {
                _angleType = AngleType.None;
            }
            else if (prevNormalNextEdgeDot > 0)
            {
                _angleType = AngleType.Inside;
            }
            else if (prevNormalNextEdgeDot < 0)
            {
                _angleType = AngleType.Outside;
            }
            else
            {
                _angleType = AngleType.None;
            }

            if (recursive)
            {
                _prevEdge.GetPrevPoint2 ().Update (false);
                _nextEdge.GetNextPoint2 ().Update (false);
            }
        }
        else if (_prevEdge != null && _nextEdge == null)
        {
            _prevEdge.Update ();

            _angularBisector = StraightLine.FromPointAndDirection (this, Vector2.zero);

            _normal = _prevEdge.GetNormal ();
            _angle = float.NaN;

            _angleType = AngleType.None;

            if (recursive)
            {
                _prevEdge.GetPrevPoint2 ().Update (false);
            }
        }
        else if (_prevEdge == null && _nextEdge != null)
        {
            _nextEdge.Update ();

            _angularBisector = StraightLine.FromPointAndDirection (this, Vector2.zero);

            _normal = _nextEdge.GetNormal ();
            _angle = float.NaN;

            _angleType = AngleType.None;

            if (recursive)
            {
                _nextEdge.GetNextPoint2 ().Update (false);
            }
        }
        else
        {
            _angularBisector = StraightLine.FromPointAndDirection (this, Vector2.zero);
            _normal = Vector2.zero;
            _angle = float.NaN;
            _angleType = AngleType.None;
        }

        _calculatedNormal = _normal;
        _normalScaleFactor = 1;

        if (!float.IsNaN (_angle))
        {
            float radAngle = _angle * Mathf.Deg2Rad;
            float sinus = Mathf.Sin (radAngle / 2);

            if (sinus != 0)
            {
                _calculatedNormal = (1 / sinus) * _normal;
                _normalScaleFactor = 1 + (_calculatedNormal.magnitude - 1);

                //Debug.Log (_angle + " " + sinus + " " + _normalScaleFactor);
            }
            else
            {
                _calculatedNormal = _normal;
                _normalScaleFactor = 1;
            }
        }
    }
示例#46
0
 public void SetTrigMode(AngleType newAngleType)
 {
     selectedAngleType = newAngleType;
 }