0
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;
}

Hi, I am trying to implement the "delta" method, but I have no way in telling if it's correct. The method says it returns "twice the signed area of oriented triangle." The instructions given were a little iffy on how we're suppose to calculate Instructions

I saw the matrix and a little bit of research showed cross product would work, but now I feel I would need to create a helper method that would determine if the three points are clockwise, counter clockwise, or colinear, which I have some idea on how to do. I just need help in determining if my delta method is correct.

  • Possible [duplicate](http://stackoverflow.com/q/1165647/230513); note that [collinear points make the determinant zero](http://math.stackexchange.com/q/184843). – trashgod Sep 27 '14 at 00:29
  • Sorry if it is a duplicate, I had some idea on determining clockwise-ness, but I'm not sure I implemented my delta method correctly and I'm not sure on how to go about and test if it's correct without pre-determined polygons – kindofastudent Sep 27 '14 at 00:56
  • Why not try a few test cases with known chirality? – trashgod Sep 27 '14 at 01:13
  • I'm sorry not sure what you mean by "chirality." I only have test cases with x and y coordinates of polygons, but no information on them – kindofastudent Sep 27 '14 at 01:16
  • [Chirality](http://en.wikipedia.org/wiki/Chirality); try one polygon and its mirror image. – trashgod Sep 27 '14 at 01:23
  • @trashgod Well I did use a determinant formula the opposite would be it's negative which worked, but why does the picture say I should use a static helper method to computer delta(a,b,c) when I can return it in one line unless I'm doing something wrong or there's more to the method then just finding the determinant of the matrix – kindofastudent Sep 27 '14 at 01:37
  • A function may be more readable. – trashgod Sep 27 '14 at 01:49

0 Answers0