• Advertisement
Sign in to follow this  

Center of 4 Points

This topic is 4702 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
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;

Share this post


Link to post
Share on other sites
You rock. I had the right idea, but I was going about it incorrectly.

Thank you

Share this post


Link to post
Share on other sites
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 !)

Share this post


Link to post
Share on other sites
(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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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:

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement