public RelativeEdgePosition Intersect(EdgeInterface e, out double t) { Point a = this.Org; Point b = this.Dest; Point c = e.Org; Point d = e.Dest; Point n = new Point((d - c).Y, (c - d).X); double denom = DotProduct(n, b - a); if (denom == 0.0) { RelativePointPosition aClass = Geometry.Point.Classify(this.Org, (Edge)e); if ((aClass == RelativePointPosition.LEFT) || (aClass == RelativePointPosition.RIGHT)) { t = 0.0; return(RelativeEdgePosition.PARALLEL); } else { t = 0.0; return(RelativeEdgePosition.COLLINEAR); } } double num = DotProduct(n, a - c); t = -num / denom; return(RelativeEdgePosition.SKEW); }
private static void SupportingLine(Point s, Polygon p, RelativePointPosition side) { Rotation rotation = (side == RelativePointPosition.LEFT) ? Rotation.CLOCKWISE : Rotation.COUNTERCLOCKWISE; var a = p.V(); var b = p.Neighbor(rotation); RelativePointPosition c = Geometry.Point.Classify((Point)b, s, (Point)a); while ((c == side) || (c == RelativePointPosition.BEYOND) || (c == RelativePointPosition.BETWEEN)) { p.Advance(rotation); a = p.V(); b = p.Neighbor(rotation); c = Geometry.Point.Classify((Point)b, s, (Point)a); } }
public static void FillViewDots(Views.ViewInterface view, List <ViewItemInterface> scene, Func <Point, RelativePointPosition> func, System.Drawing.Color color, int offset = 0) { for (double y = offset; y < view.Height; y += 10) { for (double x = offset; x < view.Width; x += 10) { var point = new Point(x, y); RelativePointPosition pos = func(point); bool inside = pos == RelativePointPosition.RIGHT || pos == RelativePointPosition.BETWEEN || pos == RelativePointPosition.ORIGIN || pos == RelativePointPosition.DESTINTION; if (inside) { scene.Add(new PointView(point, color)); ///scene1.Add(new PointView(point, inside ? System.Drawing.Color.Green : System.Drawing.Color.Red)); } } } }
public static bool PointInConvexPolygon(Point s, Polygon p) { if (p.Size() == 1) { return(s.Equals(p.Point())); } if (p.Size() == 2) { RelativePointPosition c = Geometry.Point.Classify(s, p.Edge()); return(((c == RelativePointPosition.BETWEEN) || c == RelativePointPosition.ORIGIN) || (c == RelativePointPosition.DESTINTION)); } var org = p.V(); for (int i = 0; i < p.Size(); i++, p.Advance(Rotation.CLOCKWISE)) { if (Geometry.Point.Classify(s, p.Edge()) == RelativePointPosition.LEFT) { p.SetV(org); return(false); } } return(true); }