Skip to content

Added centroid method#4173

Merged
d-torrance merged 5 commits intoMacaulay2:developmentfrom
seangrate:barycenter
Mar 28, 2026
Merged

Added centroid method#4173
d-torrance merged 5 commits intoMacaulay2:developmentfrom
seangrate:barycenter

Conversation

@seangrate
Copy link
Copy Markdown
Contributor

Added a method to compute the centroid of a polyhedron. This implements the feature requested in #4172.

Copy link
Copy Markdown
Member

@mahrud mahrud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This is great, I left a few comments ranging from typos to just some FYIs in case you're interested.

"minimalNonFaces",
"stanleyReisnerRing"
"stanleyReisnerRing",
"centroid"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sidenote: this way next time someone adds a function they don't edit two lines, which can sometimes avoid merge conflicts.

Suggested change
"centroid"
"centroid",

centroid
(centroid,Polyhedron)
Headline
Computes the centroid or barycenter of a polyhedron.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Following the convention in the rest of the package:

Suggested change
Computes the centroid or barycenter of a polyhedron.
computes the centroid or barycenter of a polyhedron

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least in Polyhedra/documentation/documentation.m2, it looks like the main convention is a capitalized first letter and the phrase ends with a period.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, that's definitely not the suggestion of the style guide, but from the toc it seems only a few nodes are like that.

:Matrix
Description
Text
The centroid a polyhedron is the center of mass of the polyhedron.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The centroid a polyhedron is the center of mass of the polyhedron.
The centroid of a polyhedron is the center of mass of the polyhedron.

Comment on lines +127 to +128
Caveat
The polyhedron must be compact.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Others can correct me if I'm mistaken, but I believe this is meant for the caveats of the algorithm or implementation, not assumptions of the definition. You could mention in the Inputs section that P must be compact.

Comment on lines +313 to +316
sum for delta in barycentricTriangulation P list (
barycenter := (sum delta) / #delta;
(volume convexHull delta / totalVolume) * barycenter
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is totally fine as as, but FYI, this also works:

Suggested change
sum for delta in barycentricTriangulation P list (
barycenter := (sum delta) / #delta;
(volume convexHull delta / totalVolume) * barycenter
)
sum(barycentricTriangulation P, delta -> (
barycenter := (sum delta) / #delta;
(volume convexHull delta / totalVolume) * barycenter
)
)

The advantage (which is negligible here) is that unlike this way we don't need to construct a list and then sum it, we just sum as we go.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't realize sum could do this, thanks!

@d-torrance d-torrance merged commit 7d6815c into Macaulay2:development Mar 28, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants