Exemplo n.º 1
0
        public Side GetSide(Vector2D pt)
        {
            return((Side)Math.Sign(StartToEnd.Cross(pt - Start)));

            /*
             * //its the basic idea of the crossproduct in R3 with a garuanteed 0 for z.
             * return (Side)Math.Sign(Start.X * (End.Y - pt.Y) + End.X * (pt.Y - Start.Y) + pt.X * (Start.Y - End.Y));*/
        }
Exemplo n.º 2
0
        public float GetIntersectionRatio(Vector2D start, Vector2D dir)
        {
            //see IsIntersecting...
            Vector2D s = Start - start;

            float denom = StartToEnd.Cross(dir);

            return(dir.Cross(s) / denom);
        }
Exemplo n.º 3
0
        /**
         * Returns the sample ratio where this line would intersect the other. Segment boundaries are not considered.
         */
        public float GetIntersectionRatio(LineSegment2D other)
        {
            //see IsIntersecting...
            Vector2D ov = other.StartToEnd;
            Vector2D s  = Start - other.Start;

            float denom = StartToEnd.Cross(ov);

            return(ov.Cross(s) / denom);
        }
Exemplo n.º 4
0
 /**
  * Project the vector v on this line segment and return the ratio.
  * return = 0      v = start
  * return = 1      v = end
  * return < 0      v is on the backward extension of AB
  * return > 1      v is on the forward extension of AB
  * 0< return <1    v is interior to AB
  */
 public float GetSnapRatio(Vector2D v)
 {
     /*
      * Let the point be C (Cx,Cy) and the line be AB (Ax,Ay) to (Bx,By).
      * Let P be the point of perpendicular projection of C on AB.  The parameter
      * r, which indicates P's position along AB, is computed by the dot product
      * of AC and AB divided by the square of the length of AB:
      *
      * (1)     AC dot AB
      *  r = ---------
      ||AB||^2
      */
     return(StartToEnd.Dot(v - Start) / LengthSquared);
 }
Exemplo n.º 5
0
 /**
  * Compare this line segment to another and return true if the lines are parallel.
  */
 public bool IsParallel(LineSegment2D other, float tolerance = 0)
 {
     return(Math.Abs(StartToEnd.Cross(other.StartToEnd)) <= tolerance);
 }