// BOURKE INTERSECT ALGORITHM public bool intersects(LineSeg line) { double denom = (line.B.Y - line.A.Y) * (this.B.X - this.A.X) - (line.B.X - line.A.X) * (this.B.Y - this.A.Y); double numA = (line.B.X - line.A.X) * (this.A.Y - line.A.Y) - (line.B.Y - line.A.Y) * (this.A.X - line.A.X); double numB = (this.B.X - this.A.X) * (this.A.Y - line.A.Y) - (this.B.Y - this.A.Y) * (this.A.X - line.A.X); //check for parallel and div by 0 if (denom == 0d) { return(false); } double uA = numA / denom; double uB = numB / denom; if (uA >= 0d && uA <= 1d && uB >= 0d && uB <= 1d) { return(true); } return(false); }
private void updateLines() { lines = new LineSeg[points.Length]; for (int i = 0; i < points.Length - 1; i++) { lines[i] = new LineSeg(points [i], points [i + 1]); } lines [lines.Length - 1] = new LineSeg(points [0], points [points.Length - 1]); }
private bool raytrace(Vector2 source, Vector2 destination) { int intersects = 0; LineSeg checkLine = new LineSeg(source, destination); foreach (LineSeg line in lines) { if (checkLine.intersects(line)) { intersects++; } } return(intersects % 2 == 1); }
public static void line(SpriteBatch spriteBatch, Vector2 start, Vector2 end, Color colour) { LineSeg line = new LineSeg(start, end); spriteBatch.Draw(tex, new Rectangle((int)line.A.X, (int)line.A.Y, (int)line.length(), 5), null, colour, line.angle(), new Vector2(0F, 0F), SpriteEffects.None, 1f); }