@Test public void normal() throws Exception { center = GeometryFactory.createVector(1, 1); direction = GeometryFactory.createVector(1, 1); minorAxis = 2; majorAxis = 5; ellipse = GeometryFactory.createEllipse(center, direction, majorAxis, minorAxis); point = GeometryFactory.createVector(1-1/Math.sqrt(2), 1+1/Math.sqrt(2)); normal = ellipse.normal(point); Assert.assertEquals(-1/Math.sqrt(2), normal.getXComponent(), PRECISION); Assert.assertEquals(1/Math.sqrt(2), normal.getYComponent(), PRECISION); F1 = GeometryFactory.createVector(0, 0); F2 = GeometryFactory.createVector(2, 0); minorAxis = 2; ellipse = GeometryFactory.createEllipse(F1, F2, minorAxis); point = GeometryFactory.createVector(1, 3); normal = ellipse.normal(point); Assert.assertEquals(0, normal.getXComponent(), PRECISION); Assert.assertEquals(1, normal.getYComponent(), PRECISION); F1 = GeometryFactory.createVector(0, 0); F2 = GeometryFactory.createVector(2, 2); minorAxis = 1; ellipse = GeometryFactory.createEllipse(F1, F2, minorAxis); Assert.assertEquals(Math.sqrt(3), ellipse.getMajorAxis(), PRECISION); point = GeometryFactory.createVector(2.5, 2.5); normal = ellipse.normal(point); Assert.assertEquals(Math.sqrt(2)/2, normal.getXComponent(), PRECISION); Assert.assertEquals(Math.sqrt(2)/2, normal.getYComponent(), PRECISION); F1 = GeometryFactory.createVector(0, 0); F2 = GeometryFactory.createVector(2, 2); minorAxis = 1; ellipse = GeometryFactory.createEllipse(F1, F2, minorAxis); point = GeometryFactory.createVector(-1, -1); normal = ellipse.normal(point); Assert.assertEquals(-Math.sqrt(2)/2, normal.getXComponent(), PRECISION); Assert.assertEquals(-Math.sqrt(2)/2, normal.getYComponent(), PRECISION); center = GeometryFactory.createVector(1, 0); direction = GeometryFactory.createVector(1, 0); minorAxis = 2; majorAxis = 5; ellipse = GeometryFactory.createEllipse(center, direction, majorAxis, minorAxis); point = GeometryFactory.createVector(1, 5); normal = ellipse.normal(point); Assert.assertEquals(0, normal.getXComponent(), PRECISION); Assert.assertEquals(1, normal.getYComponent(), PRECISION); }
public Vector2D normal(Vector2D point) { Vector2D pointOnEllipse = closestPoint(point); pointOnEllipse = pointOnEllipse.subtract(this.getCenter()).rotate(-this.getOrientation()); Vector2D normal = new Vector2D(pointOnEllipse.getXComponent() * getMinorAxis()/getMajorAxis(), pointOnEllipse.getYComponent() * getMajorAxis()/getMinorAxis()); return normal.rotate(this.getOrientation()).getNormalized(); }
Ellipse2D { public Vector2D normal(Vector2D point) { Vector2D pointOnEllipse = closestPoint(point); pointOnEllipse = pointOnEllipse.subtract(this.getCenter()).rotate(-this.getOrientation()); Vector2D normal = new Vector2D(pointOnEllipse.getXComponent() * getMinorAxis()/getMajorAxis(), pointOnEllipse.getYComponent() * getMajorAxis()/getMinorAxis()); return normal.rotate(this.getOrientation()).getNormalized(); } }
Ellipse2D { public Vector2D normal(Vector2D point) { Vector2D pointOnEllipse = closestPoint(point); pointOnEllipse = pointOnEllipse.subtract(this.getCenter()).rotate(-this.getOrientation()); Vector2D normal = new Vector2D(pointOnEllipse.getXComponent() * getMinorAxis()/getMajorAxis(), pointOnEllipse.getYComponent() * getMajorAxis()/getMinorAxis()); return normal.rotate(this.getOrientation()).getNormalized(); } Ellipse2D(Vector2D center, Vector2D direction, double majorAxis, double minorAxis); }
Ellipse2D { public Vector2D normal(Vector2D point) { Vector2D pointOnEllipse = closestPoint(point); pointOnEllipse = pointOnEllipse.subtract(this.getCenter()).rotate(-this.getOrientation()); Vector2D normal = new Vector2D(pointOnEllipse.getXComponent() * getMinorAxis()/getMajorAxis(), pointOnEllipse.getYComponent() * getMajorAxis()/getMinorAxis()); return normal.rotate(this.getOrientation()).getNormalized(); } Ellipse2D(Vector2D center, Vector2D direction, double majorAxis, double minorAxis); Vector2D closestPoint(Vector2D point); Vector2D vectorBetween(Vector2D point); Vector2D normal(Vector2D point); Vector2D getCenter(); void setCenter(Vector2D center); double getOrientation(); double getMajorAxis(); double getMinorAxis(); void translate(double x, double y); void translate(Vector2D vector); }
Ellipse2D { public Vector2D normal(Vector2D point) { Vector2D pointOnEllipse = closestPoint(point); pointOnEllipse = pointOnEllipse.subtract(this.getCenter()).rotate(-this.getOrientation()); Vector2D normal = new Vector2D(pointOnEllipse.getXComponent() * getMinorAxis()/getMajorAxis(), pointOnEllipse.getYComponent() * getMajorAxis()/getMinorAxis()); return normal.rotate(this.getOrientation()).getNormalized(); } Ellipse2D(Vector2D center, Vector2D direction, double majorAxis, double minorAxis); Vector2D closestPoint(Vector2D point); Vector2D vectorBetween(Vector2D point); Vector2D normal(Vector2D point); Vector2D getCenter(); void setCenter(Vector2D center); double getOrientation(); double getMajorAxis(); double getMinorAxis(); void translate(double x, double y); void translate(Vector2D vector);  }