No BSD License  

Highlights from
Centroid of a Convex n-Dimensional Polyhedron

4.5

4.5 | 6 ratings Rate this file 5 Downloads (last 30 days) File Size: 1.46 KB File ID: #8514
image thumbnail

Centroid of a Convex n-Dimensional Polyhedron

by Michael Kleder

 

19 Sep 2005 (Updated 21 Sep 2005)

Computes the center of gravity of a convex polyhedron in any number of dimensions.

| Watch this File

File Information
Description

USAGE: C = centroid(P)
 
P = Matrix of convex polyhedron vertices: each row is a vertex, and each column is a dimension.
C = Row vector of centroid coordinates. Each column is a dimension.

Notes:
(1) This function computes the centroid by partitioning into simplices and determining the weighted sum of their centroids.
(2) Written in response to a question on comp.soft-sys.matlab

Michael Kleder, Sep 2005

MATLAB release MATLAB 7.0.4 (R14SP2)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (9)
13 Oct 2005 Birajashis Pattnaik

Ohh this is fantastic.

03 Nov 2005 Glen Lichtwark

This is a very handy function, thanx.

26 Oct 2006 fady dawoud

very nice!! a question though, does the algorithm still work if the points dont form a convex surface.

10 Nov 2006 The Author

Answer to Fady Dawoud: If the points do not form a convex polyhedron, then the function gives you an error telling you what happened.

01 May 2007 Roja B

Hi,

thank you, this is a very useful function. my only problem is when I try to use it in 2-D. how do you think I can fix this?

03 May 2007 The Author

Answer to Roja B:
As an example in 2-D, try
P=centroid([0 0;1 1;2 0]);
plot([0 1 2 0],[0 1 0 0],...
'b-',P(1),P(2),'r.');

06 Mar 2008 Charlotte B

thanks for this function! but what happens with a concave polyhedron? do you have suggestions on how to calculate the center of gravity of these shapes?

21 May 2010 Chris Godau

Very nice, thank you!
Was just about to write this myself when I found yours.
If your set of points is not convex you can of course use the convex hull:
centroid(P(unique(convhulln(P)),:))

23 Feb 2011 Raghuram

For the following p = [0 0; 1 1; 0.6667 0.6667; 0.5 0.8333; 0.1667 0.5] it gives an error saying the polygon is not convex when in fact it is.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
centroid Michael Kleder 22 Oct 2008 08:00:21
center Michael Kleder 22 Oct 2008 08:00:21
gravity Michael Kleder 22 Oct 2008 08:00:22
polyhedron Michael Kleder 22 Oct 2008 08:00:22
polgyon Michael Kleder 22 Oct 2008 08:00:22
centroid asdd 07 Nov 2008 14:56:29
centroid Lulu 22 Mar 2011 02:03:10
center Alin 19 Nov 2011 05:54:46

Contact us at files@mathworks.com