Sign in to follow this  
PaganX

Center of 4 Points

Recommended Posts

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
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
Quote:
Original post by baldurk
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:


I don't think that's a counterexample, since the centroid would still be inside the polyhedron as described.

Share this post


Link to post
Share on other sites
Quote:
Original post by kSquared
Quote:
Original post by baldurk
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:


I don't think that's a counterexample, since the centroid would still be inside the polyhedron as described.


Hmm I thought that hplus meant that the centroid wouldn't necessarily lie on the polygon. Otherwise, I don't see how it could lie outside.

Share this post


Link to post
Share on other sites
EDIT: WRONG!
counterexample...

(0, 0, a) (1, 0, b) (1, 1, c) (0.75, 0.25, d)

Center point c:
c.x = (0 + 1 + 1 + 0.75) / 4 = 0.6875
c.y = (0 + 0 + 1 + 0.25) / 4 = 0.3125
c.z = (a + b + c + d) / 4

And as you can see, c will always be outside any volume created by the points given.


EDIT: No, I'm wrong... It will always be inside the volume created. As I actuallly showed before, the center of a line segment from d1 to d2 will always be inside the volume.

[Edited by - __fold on June 6, 2005 5:14:28 AM]

Share this post


Link to post
Share on other sites
Given the question:
Quote:
Original post by PaganXHow do I got about finding the center of 4 points?


The exact and correct answer is*:
Quote:
Original post by Hexed
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;


See http://mathworld.wolfram.com/GeometricCentroid.html

The center for N points is the average, and when used with weighting, can be used for optimization problems as shown below, from the Wolfram link above:
Quote:

The centroid of n point masses also gives the location at which a school should be built in order to minimize the distance travelled by children from n cities, located at the positions of the masses, and with mi equal to the number of students from city i (Steinhaus 1999, pp. 113-116).


4 points can be use to define tetrahedral barycentric coordinates, for which the barycentric center is (.25,.25,.25,.25), or the average of the 4 points.


*No planar/polygonal constraint was given.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this