Beispiel #1
0
        static public float PointToLinear(IssoPoint2D pt, IssoPoint2D lineStart, IssoPoint2D lineEnd)
        {
            float a, b, c;

            if (lineStart.X == lineEnd.X)
            {
                b = 0; a = 1; c = -lineStart.X;
            }
            else
            if (lineStart.Y == lineEnd.Y)
            {
                b = 1; a = 0; c = lineStart.Y;
            }
            else
            {
                b = -1;
                a = (lineEnd.Y - lineStart.Y) / (lineEnd.X - lineStart.X);
                c = lineEnd.Y - lineEnd.X * a;
            }

            float d = (float)Math.Abs(((a * pt.X + b * pt.Y + c)) /
                                      (Math.Sqrt(a * a + b * b)));

            return(d);
        }
Beispiel #2
0
 public IssoRect2D(IssoPoint2D BottomLeft, float width, float height)
 {
     Corner1 = BottomLeft;
     Corner2 = new IssoPoint2D {
         X = Corner1.X + width, Y = Corner1.Y + height
     };
 }
 internal void SetLastNodeAt(IssoPoint2D pt2)
 {
     if (node2 != null)
     {
         node2.MoveTo(pt2);
     }
 }
Beispiel #4
0
        public static IssoPoint2D PurpPoint(IssoPoint2D pt, IssoPoint2D lineS, IssoPoint2D lineE)
        {
            // get dot product of e1, e2
            IssoPoint2D e1 = new IssoPoint2D()
            {
                X = lineE.X - lineS.X, Y = lineE.Y - lineS.Y
            };
            IssoPoint2D e2 = new IssoPoint2D()
            {
                X = pt.X - lineS.X, Y = pt.Y - lineS.Y
            };
            float valDp = dotProduct(e1, e2);
            // get length of vectors
            float lenLineE1 = (float)Math.Sqrt(e1.X * e1.X + e1.Y * e1.Y);
            float lenLineE2 = (float)Math.Sqrt(e2.X * e2.X + e2.Y * e2.Y);
            float cos       = valDp / (lenLineE1 * lenLineE2);
            // length of v1P'
            float projLenOfLine = cos * lenLineE2;

            if (lenLineE1 * lenLineE2 == 0)
            {
                return(pt);
            }

            IssoPoint2D p = new IssoPoint2D()
            {
                X = (lineS.X + (projLenOfLine * e1.X) / lenLineE1),
                Y = (lineS.Y + (projLenOfLine * e1.Y) / lenLineE1)
            };

            return(p);
        }
Beispiel #5
0
        public static float getEpsilon(IssoPoint2D p1, IssoPoint2D p2)
        {
            float dx1     = p2.X - p1.X;
            float dy1     = p2.Y - p1.Y;
            float epsilon = 0.003f * (dx1 * dx1 + dy1 * dy1);

            return(epsilon);
        }
Beispiel #6
0
        public ComponentLinear SplitAt(IssoPoint2D pt)
        {
            ComponentNode   node = new ComponentNode(pt);
            ComponentLinear lin  = new ComponentLinear(node, node2, Model);

            node2 = node;
            return(lin);
        }
Beispiel #7
0
 public IssoQuad2D(IssoPoint2D c1, IssoPoint2D c2, IssoPoint2D c3, IssoPoint2D c4)
 {
     // Создаём четырёхугольник по четырём точкам
     corner1 = c1;
     corner2 = c2;
     corner1 = c1;
     corner2 = c2;
 }
 public ComponentNode()
 {
     DisallowedDisplacements = new List <NodeDisplacement>();
     location = new IssoPoint2D()
     {
         X = 0, Y = 0
     };
     state = ComponentState.csNormal;
 }
Beispiel #9
0
 public IssoBinding(IssoBindingType t, ComponentNode source, ComponentNode target, float dist)
 {
     Type        = t;
     this.source = source;
     this.target = target;
     Value       = dist;
     LinePlace   = new IssoPoint2D()
     {
         X = source.Location.X, Y = source.Location.Y
     };
 }
Beispiel #10
0
        static public float LineAngle(IssoPoint2D lineStart, IssoPoint2D lineEnd)
        {
            float len = PointDst(lineStart, lineEnd);

            if (len > 0)
            {
                return((float)Math.Acos((lineEnd.X - lineStart.X) / len));
            }
            else
            {
                return(0);
            }
        }
Beispiel #11
0
        static public IssoPoint2D MirrorPoint(IssoPoint2D point, IssoPoint2D AxisPoint1, IssoPoint2D AxisPoint2)
        {
            IssoPoint2D pt = new IssoPoint2D()
            {
                X = point.X, Y = point.Y
            };
            IssoPoint2D purpPt = PurpPoint(pt, AxisPoint1, AxisPoint2);

            float dst = PointDst(pt, purpPt);

            float ang = LineAngle(AxisPoint1, AxisPoint2);

            pt.X = pt.X + Math.Sign(purpPt.X - pt.X) * dst * 2 * Math.Abs((float)Math.Cos(Math.PI / 2 - ang));
            pt.Y = pt.Y + Math.Sign(purpPt.Y - pt.Y) * dst * 2 * Math.Abs((float)Math.Sin(Math.PI / 2 - ang));

            return(pt);
        }
Beispiel #12
0
        public static bool isProjectedPointOnLineSegment(IssoPoint2D pt, ComponentLinear line)
        {
            // get dotproduct |e1| * |e2|
            IssoPoint2D e1 = new IssoPoint2D()
            {
                X = line.End.X - line.Start.X, Y = line.End.Y - line.Start.Y
            };
            float recArea = dotProduct(e1, e1);
            // dot product of |e1| * |e2|
            IssoPoint2D e2 = new IssoPoint2D()
            {
                X = pt.X - line.Start.X, Y = pt.Y - line.Start.Y
            };
            double val = dotProduct(e1, e2);

            return(val > 0 && val < recArea);
        }
Beispiel #13
0
 public static bool PointsOnLine(IssoPoint2D[] pts, IssoPoint2D[] line)
 {
     // Возвращает "истина" если все точки в pts лежат на отрезке, заданным двумя точками в Line
     for (int i = 0; i < pts.Length; i++)
     {
         IssoPoint2D p = pts[i];
         if (!((line[0].X <= p.X && p.X <= line[1].X) || (line[1].X <= p.X && p.X <= line[0].X)))
         {
             // test point not in x-range
             return(false);
         }
         if (!((line[0].Y <= p.Y && p.Y <= line[1].Y) || (line[1].Y <= p.Y && p.Y <= line[0].Y)))
         {
             // test point not in y-range
             return(false);
         }
         if (!isPointOnLineviaPDP(line[0], line[1], p))
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #14
0
 public static IssoPoint2D PurpPoint(IssoPoint2D pt, ComponentLinear line)
 {
     return(PurpPoint(pt, line.Start, line.End));
 }
 internal void MoveTo(IssoPoint2D value)
 {
     location = value;
 }
Beispiel #16
0
 public IssoRect2D(IssoPoint2D c1, IssoPoint2D c2)
 {
     Corner1 = c1;
     Corner2 = c2;
 }
Beispiel #17
0
 static public float PointToLinear(IssoPoint2D pt, ComponentLinear line)
 {
     return(PointToLinear(pt, line.Start, line.End));
 }
Beispiel #18
0
 private static float perpDotProduct(IssoPoint2D p1, IssoPoint2D p2, IssoPoint2D p)
 {
     return((p1.X - p.X) * (p2.Y - p.Y) - (p1.Y - p.Y) * (p2.X - p.X));
 }
Beispiel #19
0
 private static bool isPointOnLineviaPDP(IssoPoint2D p1, IssoPoint2D p2, IssoPoint2D p)
 {
     return(Math.Abs(perpDotProduct(p1, p2, p)) < getEpsilon(p1, p2));
 }
Beispiel #20
0
 public static float PointDst(IssoPoint2D pt1, IssoPoint2D pt2)
 {
     return((float)Math.Sqrt(Math.Pow(pt1.X - pt2.X, 2) + Math.Pow(pt1.Y - pt2.Y, 2)));
 }
Beispiel #21
0
 public static bool PointInRect(IssoPoint2D pt, IssoRect2D rect)
 {
     return((pt.X >= rect.TopLeft.X) && (pt.X <= rect.BottomRight.X) &&
            (pt.Y >= rect.BottomRight.Y) && (pt.Y <= rect.TopLeft.Y));
 }
 public ComponentNode(IssoPoint2D location) : base()
 {
     DisallowedDisplacements = new List <NodeDisplacement>();
     this.location           = location;
     state = ComponentState.csNormal;
 }
Beispiel #23
0
 private static float dotProduct(IssoPoint2D p1, IssoPoint2D p2)
 {
     return(p1.X * p2.X + p1.Y * p2.Y);
 }