Triangle implements Shape { @Override public final boolean isInside(Point2d point) { final float v1x = vertices[0].getX(); final float v1y = vertices[0].getY(); final float v2x = vertices[1].getX(); final float v2y = vertices[1].getY(); final float v3x = vertices[2].getX(); final float v3y = vertices[2].getY(); final float px = point.getX(); final float py = point.getY(); if (px > v1x && px > v2x && px > v3x) return false; if (px < v1x && px < v2x && px < v3x) return false; if (py > v1y && py > v2y && py > v3y) return false; if (py < v1y && py < v2y && py < v3y) return false; final int o1 = getOrientation(v1x, v1y, v2x, v2y, px, py); final int o2 = getOrientation(v2x, v2y, v3x, v3y, px, py); final int o3 = getOrientation(v3x, v3y, v1x, v1y, px, py); return (o1 == o2) && (o2 == o3); } Triangle(Point2d vertex1, Point2d vertex2, Point2d vertex3);  Triangle(Point2d[] vertices); final boolean isInsideOnLine(Point2d point); @Override final boolean isInside(Point2d point); @Override Rectangle calculateRegularBoundingBox(); @Override void translate(float x, float y); @Override void scale(float sc); @Override void scale(Point2d centre, float sc); @Override void scaleCentroid(float sc); @Override Point2d calculateCentroid(); @Override double calculateArea(); @Override double minX(); @Override double minY(); @Override double maxX(); @Override double maxY(); @Override double getWidth(); @Override double getHeight(); @Override Triangle transform(Matrix transform); @Override Polygon asPolygon(); Point2d firstVertex(); Point2d secondVertex(); Point2d thirdVertex(); List<Line2d> getEdges(); boolean sharesVertex(Triangle other); @Override double intersectionArea(Shape that); @Override double intersectionArea(Shape that, int nStepsPerDimention); @Override Triangle clone(); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); Map<Line2d, Point2d> intersectionSides(Line2d line); @Override double calculatePerimeter(); @Override RotatedRectangle minimumBoundingRectangle(); @Override boolean isConvex(); public Point2d[] vertices; }
@Test public void testIsInside() { final Triangle t = new Triangle( new Point2dImpl(0, 0), new Point2dImpl(0.5f, 1f), new Point2dImpl(0.5f, 0f) ); assertTrue(!t.isInside(new Point2dImpl(0.25f, 0f))); assertTrue(t.isInsideOnLine(new Point2dImpl(0.25f, 0f))); assertTrue(!t.isInside(new Point2dImpl(0.5f, 0.5f))); assertTrue(t.isInsideOnLine(new Point2dImpl(0.5f, 0.5f))); }