这种顺时针方法适用于多边形吗?

时间:2014-09-26 23:35:41

标签: java methods polygon

public class SimplePolygon {

protected int n; // number of vertices of the polygon
protected Point2D.Double[] vertices; // vertices[0..n-1] around the polygon
                                // boundary

protected SimplePolygon(int size) {
    n = size;
    this.vertices = new Point2D.Double[size];
}

protected SimplePolygon() {
    n = 0;
}

public static SimplePolygon getNewPoly(Point2D.Double[] vertex) {
    int size = vertex.length; // TODO: replace this line with your code
    SimplePolygon p = new SimplePolygon(size);
    // TODO: populate p.vertices[0..size-1] from input file
    for(int i = 0; i < vertex.length; i++){
        Point2D.Double[] pArray = p.vertices;
        pArray[i] = vertex[i];
    }
    return p;
}

public int getSize() {
    return n;
}

public Point2D.Double getVertex(int i) throws IndexOutOfBoundsException {
    Point2D.Double u = null;
    try{
        u = vertices[i];
    }catch(IndexOutOfBoundsException e){
        e.printStackTrace();
    }
    return u;
}

public static double delta(Point2D.Double a, Point2D.Double b,
        Point2D.Double c) {
    double val = (a.getX()*b.getY()*1) + (a.getY()*1*c.getX()) 
            + (1*b.getX()*c.getY()) - (a.getY()*b.getX()*1)
            - (a.getX()*1*c.getY()) - (1*b.getY()*c.getX());

    return val;
}

嗨,我正在尝试实施&#34; delta&#34;方法,但我无法确定它是否正确。该方法表示它返回&#34;两倍于定向三角形的有符号区域。&#34;给出的说明对于我们如何计算Instructions

有点不确定

我看到矩阵和一些研究表明交叉产品会起作用,但现在我觉得我需要创建一个辅助方法来确定这三个点是顺时针,逆时针还是共线,我有关于如何做的一些想法。我只需要帮助确定我的delta方法是否正确。

0 个答案:

没有答案