Center of 4 Points
Easily. Average them out. Assuming you are working in 3D:
m.x = (p1.x + p2.x + p3.x + p4.x) / 4;
m.y = (p1.y + p2.y + p3.y + p4.y) / 4;
m.z = (p1.z + p2.z + p3.z + p4.z) / 4;
m.x = (p1.x + p2.x + p3.x + p4.x) / 4;
m.y = (p1.y + p2.y + p3.y + p4.y) / 4;
m.z = (p1.z + p2.z + p3.z + p4.z) / 4;
There is no well-defined center of 4 points in 3 dimensions; the problem is over-constrained. There's a centroid, which is what the formula given calculates; that's usually good enough (but could theoretically, actually be outside the polygon circumscribed by p1,p2,p3,p4 !)
(0,0)
(10,0)
(10,8)
(10,1)
(10,2)
(10,3)
(10,5)
should give you an idea of finding the centre of some points.
try to tell me where the centre of a triangle is and how to find it.
(10,0)
(10,8)
(10,1)
(10,2)
(10,3)
(10,5)
should give you an idea of finding the centre of some points.
try to tell me where the centre of a triangle is and how to find it.
If by center you mean the point which has the smallest maximum distance to all other points, then taking the average will not work for anything more than 2 points.
Imagine 3 of your points are at coordinates (0,0,0) and 1 points is at (1,0,0). The coordinate you will get by taking the average of the 4 is (0.25, 0, 0). But you might consider the center to be (0.5, 0, 0).
Imagine 3 of your points are at coordinates (0,0,0) and 1 points is at (1,0,0). The coordinate you will get by taking the average of the 4 is (0.25, 0, 0). But you might consider the center to be (0.5, 0, 0).
Quote:Original post by hplus0603
There is no well-defined center of 4 points in 3 dimensions; the problem is over-constrained. There's a centroid, which is what the formula given calculates; that's usually good enough (but could theoretically, actually be outside the polygon circumscribed by p1,p2,p3,p4 !)
Can you give an example where this would be the case? I'm having a hard time visualizing that.
1) Take a piece of normal paper
2) Fold it across a diagonal, so that each half is at right angles to the other
3) Mentally estimate the average of the points.
That should be off the polygon(s) described by the four points. The more points you have the easier, but I'm not sure if it's possible for 3 or less.
bad diagram:
2) Fold it across a diagonal, so that each half is at right angles to the other
3) Mentally estimate the average of the points.
That should be off the polygon(s) described by the four points. The more points you have the easier, but I'm not sure if it's possible for 3 or less.
bad diagram:
May I also add some thoughts?
If the four points are a quad then...
Draw any quad and draw a line between point 1 and point 3, call it D1.
Then draw a line between point 2 and point 4, call it D2.
The center of D1:
d1.x = (p1.x + p3.x) / 2
d1.y = (p1.y + p3.y) / 2
d1.z = (p1.z + p3.z) / 2
The center of D2:
d2.x = (p2.x + p4.x) / 2
d2.y = (p2.y + p4.y) / 2
d2.z = (p2.z + p4.z) / 2
The center (q1) of a line between d1 and d2 is.
q1.x = (d1.x + d2.x) / 2
q1.y = (d1.y + d2.y) / 2
q1.z = (d1.z + d2.z) / 2
Substitute it:
q1.x = ((p1.x + p3.x) / 2 + (p2.x + p4.x) / 2) / 2
q1.y = ((p1.y + p3.y) / 2 + (p2.y + p4.y) / 2) / 2
q1.z = ((p1.z + p3.z) / 2 + (p2.z + p4.z) / 2) / 2
Simplifies to:
q1.x = (p1.x + p2.x + p3.x + p4.x) / 4;
q1.y = (p1.y + p2.y + p3.y + p4.y) / 4;
q1.z = (p1.z + p2.z + p3.z + p4.z) / 4;
...and as everybody can see. This will only make sense for quads where all the points are in the same plane. The point q1 will always be inside the quad only if the quad is convex.
EDIT: Small errors...
If the four points are a quad then...
Draw any quad and draw a line between point 1 and point 3, call it D1.
Then draw a line between point 2 and point 4, call it D2.
The center of D1:
d1.x = (p1.x + p3.x) / 2
d1.y = (p1.y + p3.y) / 2
d1.z = (p1.z + p3.z) / 2
The center of D2:
d2.x = (p2.x + p4.x) / 2
d2.y = (p2.y + p4.y) / 2
d2.z = (p2.z + p4.z) / 2
The center (q1) of a line between d1 and d2 is.
q1.x = (d1.x + d2.x) / 2
q1.y = (d1.y + d2.y) / 2
q1.z = (d1.z + d2.z) / 2
Substitute it:
q1.x = ((p1.x + p3.x) / 2 + (p2.x + p4.x) / 2) / 2
q1.y = ((p1.y + p3.y) / 2 + (p2.y + p4.y) / 2) / 2
q1.z = ((p1.z + p3.z) / 2 + (p2.z + p4.z) / 2) / 2
Simplifies to:
q1.x = (p1.x + p2.x + p3.x + p4.x) / 4;
q1.y = (p1.y + p2.y + p3.y + p4.y) / 4;
q1.z = (p1.z + p2.z + p3.z + p4.z) / 4;
...and as everybody can see. This will only make sense for quads where all the points are in the same plane. The point q1 will always be inside the quad only if the quad is convex.
EDIT: Small errors...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement