public static bool PointOnLine(Vector point, Line line) { Vector a, b; Vector ap = Geom.Sub(point, line.a); Vector ab = Geom.Sub(line.b, line.a); // colinear check if (Geom.Mul(ap, ab) != 0) { return(false); } // check x if (line.a.x < line.b.x) { a = line.a; b = line.b; } else { a = line.b; b = line.a; } if (point.x < a.x || point.x > b.x) { return(false); } // check y if (line.a.y < line.b.y) { a = line.a; b = line.b; } else { a = line.b; b = line.a; } if (point.y < a.y || point.y > b.y) { return(false); } return(true); }
private Collision GetCollision(Shape figure) { Circle circle = model.player; Polygon poly = (Polygon)figure; Vector[] dots = poly.dots.ToArray(); for (int i = 0; i < dots.Length - 1; i++) { Vector a = dots[i]; Vector b = dots[i + 1]; Line line = new Line(a, b); if (Geom.IntersectCircleLineRectangles(circle, line)) { float dist = Geom.Distance(line, circle.center); if ((dist - circle.rad) <= PRECISION) { float prevDist = Geom.Distance(line, copyCircle.center); if (dist < prevDist) { return(new Collision(line, Collision.Type.Normal)); } } } else { float distCorner = Geom.DistanceCorner(circle, line); if ((distCorner - circle.rad) <= PRECISION) { float prevDistCorner = Geom.DistanceCorner(copyCircle, line); if (distCorner < prevDistCorner) { return(new Collision(line, Collision.Type.Corner)); } } } } return(null); }