Center of 4 Points

Started by
12 comments, last by John Schultz 18 years, 10 months ago
How do I got about finding the center of 4 points?
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;
You rock. I had the right idea, but I was going about it incorrectly.

Thank you
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 !)
enum Bool { True, False, FileNotFound };
Yea what he said.
(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.
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).
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.
- k2"Choose a job you love, and you'll never have to work a day in your life." — Confucius"Logic will get you from A to B. Imagination will get you everywhere." — Albert Einstein"Money is the most egalitarian force in society. It confers power on whoever holds it." — Roger Starr{General Programming Forum FAQ} | {Blog/Journal} | {[email=kkaitan at gmail dot com]e-mail me[/email]} | {excellent webhosting}
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:

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

This topic is closed to new replies.

Advertisement