/** * Computes the normal of a plane that is defined by three points. * <p> * Edge cases: * <ul> * <li> Returns a {@code null} if the three points are on a line. * <li> Returns {@code null} if two or three points are equal. * </ul> * </p> * <p> * WARNING: This method generates garbage. * </p> * * @param firstPointOnPlane first point on the plane. Not modified. * @param secondPointOnPlane second point on the plane. Not modified. * @param thirdPointOnPlane third point on the plane. Not modified. * @return the plane normal or {@code null} when the normal could not be determined. * @throws ReferenceFrameMismatchException if the arguments are not expressed in the same reference frame. */ public static FrameVector3D getPlaneNormalGivenThreePoints(FramePoint3D firstPointOnPlane, FramePoint3D secondPointOnPlane, FramePoint3D thirdPointOnPlane) { FrameVector3D normal = new FrameVector3D(); boolean success = getPlaneNormalGivenThreePoints(firstPointOnPlane, secondPointOnPlane, thirdPointOnPlane, normal); if (!success) return null; else return normal; }
/** * Computes the normal of a plane that is defined by three points. * <p> * Edge cases: * <ul> * <li> Returns a {@code null} if the three points are on a line. * <li> Returns {@code null} if two or three points are equal. * </ul> * </p> * <p> * WARNING: This method generates garbage. * </p> * * @param firstPointOnPlane first point on the plane. Not modified. * @param secondPointOnPlane second point on the plane. Not modified. * @param thirdPointOnPlane third point on the plane. Not modified. * @return the plane normal or {@code null} when the normal could not be determined. * @throws ReferenceFrameMismatchException if the arguments are not expressed in the same reference frame. */ public static FrameVector getPlaneNormalGivenThreePoints(FramePoint firstPointOnPlane, FramePoint secondPointOnPlane, FramePoint thirdPointOnPlane) { FrameVector normal = new FrameVector(); boolean success = getPlaneNormalGivenThreePoints(firstPointOnPlane, secondPointOnPlane, thirdPointOnPlane, normal); if (!success) return null; else return normal; }
/** * Computes the normal of a plane that is defined by three points. * <p> * Edge cases: * <ul> * <li> Returns a {@code null} if the three points are on a line. * <li> Returns {@code null} if two or three points are equal. * </ul> * </p> * <p> * WARNING: This method generates garbage. * </p> * * @param firstPointOnPlane first point on the plane. Not modified. * @param secondPointOnPlane second point on the plane. Not modified. * @param thirdPointOnPlane third point on the plane. Not modified. * @return the plane normal or {@code null} when the normal could not be determined. */ public static Vector3d getPlaneNormalGivenThreePoints(Point3d firstPointOnPlane, Point3d secondPointOnPlane, Point3d thirdPointOnPlane) { Vector3d normal = new Vector3d(); boolean success = getPlaneNormalGivenThreePoints(firstPointOnPlane, secondPointOnPlane, thirdPointOnPlane, normal); if (!success) return null; else return normal; }
/** * Computes the normal of a plane that is defined by three points. * <p> * Edge cases: * <ul> * <li> Fails and returns {@code false} if the three points are on a line. * <li> Fails and returns {@code false} if two or three points are equal. * </ul> * </p> * * @param firstPointOnPlane first point on the plane. Not modified. * @param secondPointOnPlane second point on the plane. Not modified. * @param thirdPointOnPlane third point on the plane. Not modified. * @param normalToPack the vector in which the result is stored. Modified. * @return whether the plane normal is properly determined. * @throws ReferenceFrameMismatchException if the arguments are not expressed in the same reference frame, except for {@code normalToPack}. */ public static boolean getPlaneNormalGivenThreePoints(FramePoint firstPointOnPlane, FramePoint secondPointOnPlane, FramePoint thirdPointOnPlane, FrameVector normalToPack) { firstPointOnPlane.checkReferenceFrameMatch(secondPointOnPlane); firstPointOnPlane.checkReferenceFrameMatch(thirdPointOnPlane); normalToPack.setToZero(firstPointOnPlane.getReferenceFrame()); return getPlaneNormalGivenThreePoints(firstPointOnPlane.getPoint(), secondPointOnPlane.getPoint(), thirdPointOnPlane.getPoint(), normalToPack.getVector()); }
FramePoint3D point3 = new FramePoint3D(ReferenceFrame.getWorldFrame(), 0, 5, 0); FrameVector3D expectedReturn = null; FrameVector3D actualReturn = GeometryTools.getPlaneNormalGivenThreePoints(point1, point2, point3); assertEquals("test failed", expectedReturn, actualReturn); FramePoint3D point93 = new FramePoint3D(ReferenceFrame.getWorldFrame(), 0, 1, 0); FrameVector3D expectedReturn9 = null; FrameVector3D actualReturn9 = GeometryTools.getPlaneNormalGivenThreePoints(point91, point92, point93); assertEquals("test failed", expectedReturn9, actualReturn9); FramePoint3D point83 = new FramePoint3D(ReferenceFrame.getWorldFrame(), 4, 0, 0); FrameVector3D expectedReturn8 = null; FrameVector3D actualReturn8 = GeometryTools.getPlaneNormalGivenThreePoints(point81, point82, point83); assertEquals("test failed", expectedReturn8, actualReturn8); FramePoint3D point73 = new FramePoint3D(ReferenceFrame.getWorldFrame(), 0, 0, 7); FrameVector3D expectedReturn7 = null; FrameVector3D actualReturn7 = GeometryTools.getPlaneNormalGivenThreePoints(point71, point72, point73); assertEquals("test failed", expectedReturn7, actualReturn7); FrameVector3D expectedReturn1 = new FrameVector3D(p1.getReferenceFrame()); expectedReturn1.sub(p1, v1); FrameVector3D actualReturn1 = GeometryTools.getPlaneNormalGivenThreePoints(point11, point12, point13); assertTrue("Test Failed", expectedReturn1.epsilonEquals(actualReturn1, EPSILON)); FrameVector3D expectedReturn2 = new FrameVector3D(p2.getReferenceFrame()); expectedReturn2.sub(p2, v2); FrameVector3D actualReturn2 = GeometryTools.getPlaneNormalGivenThreePoints(point21, point22, point23); assertTrue("Test Failed", expectedReturn2.epsilonEquals(actualReturn2, EPSILON));