public static bool AreNear(MyPoint p1, Point p2, double radius) { return(Math.Pow(radius, 2) > Math.Pow(p1.X - p2.X, 2) + Math.Pow(p1.Y - p2.Y, 2)); }
public static bool CheckIfCollinear(MyPoint p1, MyPoint p2, MyPoint p3) { return(Math.Abs((p1.X - p2.X) * (p3.Y - p2.Y) - (p3.X - p2.X) * (p1.Y - p2.Y)) <= Globals.eps); }
public static double VectorProduct(MyPoint p1, MyPoint p2) { return(p1.X * p2.Y - p2.X * p1.Y); }
public MyPoint CopyWithoutDrawing() { MyPoint p = new MyPoint(X, Y); return(p); }
public bool IsPointInside(Point p) { //testing RemoveCollinearEdges //var edgeFirst = Edges[0]; //var edgeThird = Edges[2]; //var myEdge1 = new MyEdge(edgeFirst.second, new MyPoint(edgeFirst.second.X + 50, edgeFirst.second.Y)); //var myEdge2 = new MyEdge(new MyPoint(edgeFirst.second.X + 50, edgeFirst.second.Y), new MyPoint(edgeFirst.second.X + 100, edgeFirst.second.Y)); //edgeThird.first = myEdge2.second; //Edges.RemoveAt(1); //Edges.Insert(1, myEdge2); //Edges.Insert(1, myEdge1); List <MyEdge> ClearEdges = RemoveCollinearEdges(); MyEdge Ray = new MyEdge(new MyPoint(p.X, p.Y), new MyPoint(p.X + canvas.ActualWidth, p.Y)); int intersectCounter = 0; for (int i = 0; i < ClearEdges.Count; i++) { var previousEdge = ClearEdges[(i - 1 + ClearEdges.Count) % ClearEdges.Count]; var edge = ClearEdges[i]; var nextEdge = ClearEdges[(i + 1) % ClearEdges.Count]; if (MyEdge.DoIntersect(edge, Ray) == true) { var firstCollinear = MyPoint.CheckIfCollinear(Ray.first, edge.first, Ray.second); var secondCollinear = MyPoint.CheckIfCollinear(Ray.first, edge.second, Ray.second); if (firstCollinear == true && secondCollinear == true) { //if previosEdge.first i nextEdge.second leza //po przeciwnych stronach polprostej Ray to intersectCounter++ if ((previousEdge.first.Y > Ray.first.Y && nextEdge.second.Y < Ray.first.Y) || (previousEdge.first.Y < Ray.first.Y && nextEdge.second.Y > Ray.first.Y)) { intersectCounter++; } } else if (firstCollinear == true) { //if previousEdge.first i edge.second leza //po przeciwnych stronach polprostej Ray to intersectCounter++ i i++ if ((previousEdge.first.Y > Ray.first.Y && edge.second.Y < Ray.first.Y) || (previousEdge.first.Y < Ray.first.Y && edge.second.Y > Ray.first.Y)) { intersectCounter++; i++; } } else if (secondCollinear == true) { //if edge.first i nextEdge.second leza //po przeciwnych stronach polprostej Ray to intersectCounter++ i i++ if ((edge.first.Y > Ray.first.Y && nextEdge.second.Y < Ray.first.Y) || (edge.first.Y < Ray.first.Y && nextEdge.second.Y > Ray.first.Y)) { intersectCounter++; i++; } } else { intersectCounter++; } } } return(intersectCounter % 2 == 1); }
public MyEdge(MyPoint first, MyPoint second) { this.first = first; this.second = second; }
public static void FixPerpendicularRelation(MyPoint edgeFirst, MyPoint edgeSecond, MyPoint relationFirst, MyPoint relationSecond, bool recursive = true) { Vector v1 = new Vector(relationSecond.X - relationFirst.X, relationSecond.Y - relationFirst.Y); Vector v2 = new Vector(relationSecond.Y - relationFirst.Y, relationFirst.X - relationSecond.X); Point APoint = new Point(edgeFirst.X, edgeFirst.Y); Point BPoint = APoint + v2; Point CPoint = new Point(edgeSecond.X, edgeSecond.Y); Point DPoint = CPoint + v1; Point?intersection = PointExtension.IntersectionPoint(APoint, BPoint, CPoint, DPoint); if (intersection.HasValue == true) { edgeSecond.X = intersection.Value.X; edgeSecond.Y = intersection.Value.Y; } else { edgeFirst.X += 5.0; edgeFirst.Y += 5.0; if (recursive == true) { FixPerpendicularRelation(edgeFirst, edgeSecond, relationFirst, relationSecond, false); } } }