sagar
sagar

Reputation: 190

How Does Unitys PolygonCollider2D calculates its center?

How Does Unitys PolygonCollider2D calculates its center ?? How is PolygonCollider2d.Bounds.center Calculated ? I googled but did not found any thing I used barycenter of polyline and barycenter of polygon but that is not what unitys polygonCollider2D uses ..

Upvotes: 0

Views: 218

Answers (1)

Matt
Matt

Reputation: 1484

https://docs.unity3d.com/ScriptReference/PolygonCollider2D.html https://docs.unity3d.com/ScriptReference/Bounds.html

The official documentation shows PolygonCollider2D uses UnityEngine.Bounds.

Bounds

Description

Represents an axis aligned bounding box.

An axis-aligned bounding box, or AABB for short, is a box aligned with coordinate axes and fully enclosing some object. Because the box is never rotated with respect to the axes, it can be defined by just its center and extents, or alternatively by min and max points.

Bounding Boxs are defined such that it encompasses every single point of an object and is (usually) the minimum size possible, regardless of the shapes (convex/concave), orientation of the objects, mass of the centre, etc... it just has to grab minimum of (xyz) and maxmimum of (xyz) values.

The centre of a bounding box is therefore (max_i+min_i)/2, where i = {x, y, z}.

Upvotes: 1

Related Questions