2 * Sixth 3D engine. Author: Svjatoslav Agejenko.
3 * This project is released under Creative Commons Zero (CC0) license.
5 package eu.svjatoslav.sixth.e3d.geometry;
9 private static boolean intersectsLine(final Point2D point, Point2D p1,
13 final Point2D tmp = p1;
23 final double xp = p2.x - p1.x;
24 final double yp = p2.y - p1.y;
26 final double yp2 = point.y - p1.y;
28 final double crossX = p1.x + ((xp * yp2) / yp);
30 return point.x >= crossX;
34 public static boolean pointWithinPolygon(final Point2D point,
35 final Point2D p1, final Point2D p2, final Point2D p3) {
37 int intersectionCount = 0;
39 if (intersectsLine(point, p1, p2))
42 if (intersectsLine(point, p2, p3))
45 if (intersectsLine(point, p3, p1))
48 return intersectionCount == 1;