Example #1
0
 /// <summary>
 /// Default constructor (0, 0, 0)
 /// </summary>
 public Node()
 {
     _Position = new Point3D(0, 0, 0);
     _Passable = true;
     _IncomingArcs = new ArrayList();
     _OutgoingArcs = new ArrayList();
 }
Example #2
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="PositionX">X coordinate.</param>
 /// <param name="PositionY">Y coordinate.</param>
 /// <param name="PositionZ">Z coordinate.</param>
 public Node(double PositionX, double PositionY, double PositionZ)
 {
     _Position = new Point3D(PositionX, PositionY, PositionZ);
     _Passable = true;
     _IncomingArcs = new ArrayList();
     _OutgoingArcs = new ArrayList();
 }
Example #3
0
 /// <summary>
 /// Modifies X, Y and Z coordinates
 /// </summary>
 /// <param name="PositionX">X coordinate.</param>
 /// <param name="PositionY">Y coordinate.</param>
 /// <param name="PositionZ">Z coordinate.</param>
 public void ChangeXYZ(double PositionX, double PositionY, double PositionZ)
 {
     Position = new Point3D(PositionX, PositionY, PositionZ);
 }
Example #4
0
        /// <summary>
        /// Returns the projection of a point on the line defined with two other points.
        /// When the projection is out of the segment, then the closest extremity is returned.
        /// </summary>
        /// <exception cref="ArgumentNullException">None of the arguments can be null.</exception>
        /// <exception cref="ArgumentException">P1 and P2 must be different.</exception>
        /// <param name="Pt">Point to project.</param>
        /// <param name="P1">First point of the line.</param>
        /// <param name="P2">Second point of the line.</param>
        /// <returns>The projected point if it is on the segment / The closest extremity otherwise.</returns>
        public static Point3D ProjectOnLine(Point3D Pt, Point3D P1, Point3D P2)
        {
            if ( Pt==null || P1==null || P2==null ) throw new ArgumentNullException("None of the arguments can be null.");
            if ( P1.Equals(P2) ) throw new ArgumentException("P1 and P2 must be different.");
            Vector3D VLine = new Vector3D(P1, P2);
            Vector3D V1Pt = new Vector3D(P1, Pt);
            Vector3D Translation = VLine*(VLine|V1Pt)/VLine.SquareNorm;
            Point3D Projection = P1+Translation;

            Vector3D V1Pjt = new Vector3D(P1, Projection);
            double D1 = V1Pjt|VLine;
            if ( D1<0 ) return P1;

            Vector3D V2Pjt = new Vector3D(P2, Projection);
            double D2 = V2Pjt|VLine;
            if ( D2>0 ) return P2;

            return Projection;
        }
Example #5
0
 /// <summary>
 /// Returns the distance between two points.
 /// </summary>
 /// <param name="P1">First point.</param>
 /// <param name="P2">Second point.</param>
 /// <returns>Distance value.</returns>
 public static double DistanceBetween(Point3D P1, Point3D P2)
 {
     return Math.Sqrt((P1.X-P2.X)*(P1.X-P2.X)+(P1.Y-P2.Y)*(P1.Y-P2.Y));
 }
Example #6
0
 /// <summary>
 /// This function will find the closest node from a geographical position in space.
 /// </summary>
 /// <param name="PtX">X coordinate of the point from which you want the closest node.</param>
 /// <param name="PtY">Y coordinate of the point from which you want the closest node.</param>
 /// <param name="PtZ">Z coordinate of the point from which you want the closest node.</param>
 /// <param name="Distance">The distance to the closest node.</param>
 /// <param name="IgnorePassableProperty">if 'false', then nodes whose property Passable is set to false will not be taken into account.</param>
 /// <returns>The closest node that has been found.</returns>
 public Node ClosestNode(double PtX, double PtY, double PtZ, out double Distance, bool IgnorePassableProperty)
 {
     Node NodeMin = null;
     double DistanceMin = -1;
     Point3D P = new Point3D(PtX, PtY, PtZ);
     foreach (Node N in LN)
     {
         if (!IgnorePassableProperty && N.Passable == false) continue;
         double DistanceTemp = Point3D.DistanceBetween(N.Position, P);
         if (DistanceMin == -1 || DistanceMin > DistanceTemp)
         {
             DistanceMin = DistanceTemp;
             NodeMin = N;
         }
     }
     Distance = DistanceMin;
     return NodeMin;
 }
Example #7
0
 /// <summary>
 /// This function will find the closest arc from a geographical position in space using projection.
 /// </summary>
 /// <param name="PtX">X coordinate of the point from which you want the closest arc.</param>
 /// <param name="PtY">Y coordinate of the point from which you want the closest arc.</param>
 /// <param name="PtZ">Z coordinate of the point from which you want the closest arc.</param>
 /// <param name="Distance">The distance to the closest arc.</param>
 /// <param name="IgnorePassableProperty">if 'false', then arcs whose property Passable is set to false will not be taken into account.</param>
 /// <returns>The closest arc that has been found.</returns>
 public Arc ClosestArc(double PtX, double PtY, double PtZ, out double Distance, bool IgnorePassableProperty)
 {
     Arc ArcMin = null;
     double DistanceMin = -1;
     Point3D P = new Point3D(PtX, PtY, PtZ);
     foreach (Arc A in LA)
     {
         if (IgnorePassableProperty && A.Passable == false) continue;
         Point3D Projection = Point3D.ProjectOnLine(P, A.StartNode.Position, A.EndNode.Position);
         double DistanceTemp = Point3D.DistanceBetween(P, Projection);
         if (DistanceMin == -1 || DistanceMin > DistanceTemp)
         {
             DistanceMin = DistanceTemp;
             ArcMin = A;
         }
     }
     Distance = DistanceMin;
     return ArcMin;
 }
Example #8
0
 /// <summary>
 /// Constructs a Vector3D with two points.
 /// </summary>
 /// <param name="P1">First point of the vector.</param>
 /// <param name="P2">Second point of the vector.</param>
 public Vector3D(Point3D P1, Point3D P2)
 {
     DX = P2.X-P1.X; DY = P2.Y-P1.Y; DZ = P2.Z-P1.Z;
 }