public static bool IsLayIn(this Point2D pt, Line2D line)
        {
            Vector2D vs = pt - line.StartPoint;
            Vector2D ve = pt - line.EndPoint;
            Vector2D v2 = line.EndPoint - line.StartPoint;



            if ((pt.DistanceTo(line.StartPoint) <= 1e-10) || (pt.DistanceTo(line.EndPoint) <= 1e-10))
            {
                return(false);
            }
            //else if (vs.IsParallelTo(ve,Angle.FromDegrees(1e-20)))
            else if (Math.Abs(vs.AngleTo(ve).Radians - Math.PI) <= 1e-10 || Math.Abs(vs.AngleTo(ve).Radians - 0) <= 1e-10)
            {
                if ((v2.Length > vs.Length) && (v2.Length > ve.Length) && (vs.Length * ve.Length != 0))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Example #2
0
        public static Angle CounterClockwiseRotationToXAxis(this Vector2D vector)
        {
            var rotation = vector.AngleTo(Vector2D.XAxis);

            return((vector.Y > 0d)
                ? -1 * rotation
                : rotation);
        }
        public override void Run(List <Point> points, List <Line> lines, List <Polygon> polygons, ref List <Point> outPoints, ref List <Line> outLines, ref List <Polygon> outPolygons)
        {
            if (points.Count == 1)
            {
                outPoints.Add(points[0]); return;
            }
            var(minPoint, idx) = HelperMethods.GetMinPoint(points, 'y');
            var minVec = new Vector2D(new Point(minPoint.X + 1234, minPoint.Y));

            points.Sort((a, b) =>
            {
                if (HelperMethods.CheckTurn(new Line(minPoint, a), b) == Enums.TurnType.Colinear)
                {
                    return(Point.GetSqrDistance(a, minPoint).CompareTo(Point.GetSqrDistance(b, minPoint)));
                }


                return(minVec.AngleTo(new Vector2D(minPoint.VectorTo(a))).Degrees
                       .CompareTo(minVec.AngleTo(new Vector2D(minPoint.VectorTo(b))).Degrees));
            });
            for (int i = 1; i < points.Count - 1; ++i)
            {
                if (HelperMethods.CheckTurn(new Line(points[0], points[i]), points[i + 1]) == Enums.TurnType.Colinear)
                {
                    points.RemoveAt(i--);
                }
            }
            if (points.Count <= 3)
            {
                outPoints.AddRange(points); return;
            }

            Stack <Point> st = new Stack <Point>();

            st.PushRange(points.GetRange(0, 3));
            for (int i = 3; i < points.Count; ++i)
            {
                while (HelperMethods.CheckTurn(new Line(st.GetSecondTop(), st.Peek()), points[i])
                       != Enums.TurnType.Left)
                {
                    st.Pop();
                }
                st.Push(points[i]);
            }
            outPoints.AddRange(st);
        }
        /// <summary>
        /// The angle made by a combined/magnitude vector with the horizontal axis
        /// </summary>
        /// <param name="v"></param>
        /// <param name="v2"></param>
        /// <returns></returns>
        public static double CombinedAngle(this Vector2D v, Vector2D v2)
        {
            Vector2D vector = v.Add(v2);
            Vector2D horizontalunitVector = new Vector2D();

            // double length = v2.Length;
            //double ab = Vector2D.AngleBetween(v, v2);
            return(vector.AngleTo(horizontalunitVector).Degrees);
        }
Example #5
0
        // gets the relative side of an element to another
        // so if A is to the left of B, returns Side.Left
        public static Side RelativeSide(Point2D pointA, Point2D pointB)
        {
            Vector2D vec = (pointB - pointA);

            double ang  = vec.AngleTo(new Vector2D(0, 1)).Degrees;
            Side   side = FromAngle(ang);

            return(side);
        }
        public void AngleTo_Tests()
        {
            var v = new Vector2D(1, 0);
            var l = v.Angle;

            Assert.AreEqual(0, l);

            var v1 = new Vector2D(0, 1);

            l = v1.Angle;
            Assert.AreEqual(System.Math.PI / 2, l);

            var v2 = new Vector2D(-1, 0);

            l = v2.Angle;
            Assert.AreEqual(System.Math.PI, l);

            var v3 = new Vector2D(0, -1);

            l = v3.Angle;
            Assert.AreEqual(3 * System.Math.PI / 2, l);

            var v4 = new Vector2D(1, -1);

            l = v4.Angle;
            Assert.AreEqual(1.75 * System.Math.PI, l);

            var a = v.AngleTo(v1);

            Assert.AreEqual(-System.Math.PI / 2, a);

            a = v.AngleTo(v2);
            Assert.AreEqual(-System.Math.PI, a);

            a = v.AngleTo(v3);
            Assert.AreEqual(-(3 * System.Math.PI / 2), a);

            a = v.AngleTo(v4);
            Assert.AreEqual(-(1.75 * System.Math.PI), a);
        }
Example #7
0
        private double[] SolveBetter2(double k1, double k2, Point2D p0, Point2D p1, double offset = 0)
        {
            double   km    = 0.5 * (k1 + k2);
            Vector2D G     = p1 - p0;
            Vector2D CDir1 = new Vector2D(GetDir(k1)[0], GetDir(k1)[1]).Rotate(Angle.FromDegrees(90));
            Vector2D CDir2 = new Vector2D(GetDir(k2)[0], GetDir(k2)[1]).Rotate(Angle.FromDegrees(90));
            Vector2D CDirM = new Vector2D(GetDir(km)[0], GetDir(km)[1]).Rotate(Angle.FromDegrees(90));
            Point2D  p21   = new Point2D(GetCoord(k1)[0], GetCoord(k1)[1]) + CDir1 * offset;
            Point2D  p22   = new Point2D(GetCoord(k2)[0], GetCoord(k2)[1]) + CDir2 * offset;
            Point2D  p2m   = new Point2D(GetCoord(km)[0], GetCoord(km)[1]) + CDirM * offset;
            Vector2D T1    = p21 - p0;
            Vector2D T2    = p22 - p0;
            Vector2D Tm    = p2m - p0;

            Angle A1 = G.SignedAngleTo(T1);
            Angle A2 = G.SignedAngleTo(T2);
            Angle Am = G.SignedAngleTo(Tm);

            if (Math.Abs(A1.Degrees - G.AngleTo(T1).Degrees) > 1e-3)
            {
                A1 = -A1;
            }
            if (Math.Abs(A2.Degrees - G.AngleTo(T2).Degrees) > 1e-3)
            {
                A2 = A2 - Angle.FromDegrees(360.0);
            }
            if (Math.Abs(Am.Degrees - G.AngleTo(Tm).Degrees) > 1e-3)
            {
                Am = Am - Angle.FromDegrees(360.0);
            }
            if (Am.Degrees * A1.Degrees > 0)
            {
                return(new double[] { km, k2 });
            }
            else
            {
                return(new double[] { k1, km });
            }
        }
Example #8
0
        public override double Intersect(BasinBase otherBasin)
        {
            var other = (MeridianBase)otherBasin;
            var Qt    = new Vector2D(
                other.Q.X * Math.Cos(Lambda.Value - otherBasin.Lambda.Value),
                other.Q.Y);

            Beta_traverse = Qt.AngleTo(Qb /*or Q?*/.ToVector2D()).Radians;
            return(Triangles.SinusesTheorem(
                       Math.PI / 2 + Delta_g_meridian,
                       r,
                       Beta_traverse)
                   -
                   //r;
                   otherBasin.r); //there's deformation
        }
Example #9
0
        private void UpdateCurrentState()
        {
            int[] idx = new int[3];
            idx[0] = 1;
            idx[1] = Arm.Compartments.Length * 4 / 10;
            idx[2] = Arm.Compartments.Length - 1;

            int i = 0;

            Vector2D target = Targets.First().Position;

            for (i = 0; i < 3; i++)
            {
                IEnumerable <Node> nodes     = Enumerable.Concat(Arm.UpperNodes.Skip(idx[i]), Arm.LowerNodes.Skip(idx[i]));
                double             totalMass = nodes.Sum(v => v.Mass);

                double avx = nodes.Sum(v => v.Position.PositionX * v.Mass) / totalMass;
                double avy = nodes.Sum(v => v.Position.PositionY * v.Mass) / totalMass;

                Vector2D point = new Vector2D(avx, avy);

                CurrentState[i * 2 + 4] = point.Norm - target.Norm;
                CurrentState[i * 2 + 5] = target.AngleTo(point);

                if (i == 0)
                {
                    CurrentState[0] = target.Norm;
                    CurrentState[1] = (new Vector2D(1, 0)).AngleTo(target);
                    Vector2D vel = new Vector2D(
                        nodes.Sum(v => v.Velocity.PositionX) / totalMass,
                        nodes.Sum(v => v.Velocity.PositionY) / totalMass);
                    CurrentState[2] = vel.Norm < 1e-7 ? 0 : vel.Norm * System.Math.Cos(point.AngleTo(vel));
                    CurrentState[3] = vel.Norm < 1e-7 ? 0 : vel.Norm * System.Math.Sin(point.AngleTo(vel));
                }
            }

            CurrentState[10] = System.Math.Sign(CurrentState[8]);
            CurrentState[11] = System.Math.Sign(CurrentState[9]);

            CurrentState.IsTerminal = Terminal;
        }
Example #10
0
        private ShearWallPanelResponse DetermineWallResponse(AnalyticalWallLateral wall,
                                                             ShearWallPanelRigidAnalysisParameters wallStiffness, LateralLevelForce force)
        {
            Force directXShear = (Force)(wallStiffness.Kx * force.DirectX / LevelStiffness.X);
            Force directYShear = (Force)(wallStiffness.Ky * force.DirectY / LevelStiffness.Y);

            Vector2D directVector = new Vector2D(directXShear.Value, directYShear.Value);

            var wallUnitVector = wall.WallLine.ToVector2D().Normalize();

            var response = new ShearWallPanelResponse(wall.UniqueId, force.LoadPattern, wall.WallLine);

            response.DirectShear = directVector.AngleTo(wallUnitVector).Degrees < 90
                ? new Force(directVector.Length, ForceUnit.Kip)
                : new Force(-directVector.Length, ForceUnit.Kip);

            response.TorsionalShear = (Force)(wallStiffness.K * wallStiffness.SignedOffsetFromCenterOfRigidity *
                                              force.TotalT(LateralLevel.CenterOfRigidity) / LevelStiffness.J);

            return(response);
        }
Example #11
0
        public override void TrackingJob(double elapsed)
        {
            Point2D  cameraPos     = Camera.Position;
            Vector2D cameraBearing = Camera.Bearing;
            Point2D  targetPos     = Target.Position;
            Vector2D currentLos    = targetPos - cameraPos;

            if (_PreviousCameraPos != null && _PreviousTargetPos != null)
            {
                Vector2D previousLos = _PreviousTargetPos - _PreviousCameraPos;
                double   LOS_rate    = previousLos.AngleTo(currentLos) / (elapsed * 1000); // = rad par secondes
                double   PN          = NAVIGATION_CONSTANT * LOS_rate;

                double target2bearing = currentLos.AngleTo(cameraBearing);
                double correction     = BEARING_CORRECTION_CONSTANT * target2bearing;

                double newAzimutSpeed = Math.Sign(target2bearing) * PN - correction;

                NewTrackingKineticOutputComputed(newAzimutSpeed, 0);
            }

            _PreviousCameraPos = cameraPos;
            _PreviousTargetPos = targetPos;
        }
Example #12
0
 public Angle AngleTo()
 {
     return(P1.AngleTo(P2));
 }