/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package kcl.waterloo.math.geom;

import java.awt.geom.Point2D;
import java.util.Collection;
import math.geom2d.conic.Ellipse2D;
import math.geom2d.line.Line2D;

/**
 *
 * @author ML
 */
public class Ellipse {

    public static Point2D intersections(java.awt.geom.Ellipse2D e0, double x0, double y0, double x1, double y1) {
        Ellipse2D e1 = new Ellipse2D(e0.getCenterX(), e0.getCenterY(), e0.getWidth() / 2d, e0.getHeight() / 2d);
        Line2D ray = new Line2D(x0, y0, x1, y1);
        Collection x2;
        try {
            x2 = e1.intersections(ray);
        } catch (Exception ex) {
            return null;
        }
        if (x2.size() > 0) {
            math.geom2d.Point2D p = (math.geom2d.Point2D) x2.toArray()[0];
            return new Point2D.Double(p.x(), p.y());
        } else {
            return null;
        }
    }
}

 

Ads help maintain this website.