Help me please with how to find Centroid of Quadrilateral? I have this constructor:
public Quadrilateral(Point a, Point b, Point c, Point d) {
if (a == null || b == null || c == null || d == null) {
throw new IllegalArgumentException();
}
if (collinear(a, b, c)) {
throw new IllegalArgumentException();
}
double[][] points = { { a.getX(), a.getY() }, { b.getX(), b.getY() },
{ c.getX(), c.getY() }, { d.getX(), d.getY() } };
if (!isConvex(points)) {
throw new IllegalArgumentException();
}
this.a = a;
this.b = b;
this.c = c;
this.d = d;
}
Then I find four centroids of triangles inside quadrilateral:
public Point centroid() {
Point center1 = centroidTriangle(a,b,c);
Point center2 = centroidTriangle(a,c,d);
Point center3 = centroidTriangle(a,d,b);
Point center4 = centroidTriangle(b,d,c);
return null;
}
private Point centroidTriangle(Point a, Point b, Point c) {
double xx = (a.getX() + b.getX() + c.getX()) / 3;
double xy = (a.getY() + b.getY() + c.getY()) / 3;
return new Point(xx, xy);
}
Then I need to find two diagonals between "leftUp" - "rightDown" and "leftDown"-"rightUp" centroids. But how can I find position of centroid to make correct pairs of them? And how to find then centroid of all quadrilateral?
Good day. After finding centers of triangles you need to find intersection of lines which made with (center1,center2) and (center3,center4). So point of intersection is Centroid of Quadrilateral
Segment: