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
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.