Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The center of gravity (also known as "center of mass" or "centroid" can be calculated with the following formula:</p> <pre><code>X = SUM[(Xi + Xi+1) * (Xi * Yi+1 - Xi+1 * Yi)] / 6 / A Y = SUM[(Yi + Yi+1) * (Xi * Yi+1 - Xi+1 * Yi)] / 6 / A </code></pre> <p>Extracted from <a href="http://en.wikipedia.org/wiki/Centroid" rel="noreferrer">Wikipedia</a>: The centroid of a non-self-intersecting closed polygon defined by n vertices (x0,y0), (x1,y1), ..., (xn−1,yn−1) is the point (Cx, Cy), where<br> <img src="https://i.stack.imgur.com/qUUMG.png" alt="X coordinate of the center"><br> <img src="https://i.stack.imgur.com/VJM7O.png" alt="Y coordinate of the center"><br> and where A is the polygon's signed area,<br> <img src="https://i.stack.imgur.com/STuAL.png" alt="Area formula"></p> <p>Example using VBasic:</p> <pre><code>' Find the polygon's centroid. Public Sub FindCentroid(ByRef X As Single, ByRef Y As _ Single) Dim pt As Integer Dim second_factor As Single Dim polygon_area As Single ' Add the first point at the end of the array. ReDim Preserve m_Points(1 To m_NumPoints + 1) m_Points(m_NumPoints + 1) = m_Points(1) ' Find the centroid. X = 0 Y = 0 For pt = 1 To m_NumPoints second_factor = _ m_Points(pt).X * m_Points(pt + 1).Y - _ m_Points(pt + 1).X * m_Points(pt).Y X = X + (m_Points(pt).X + m_Points(pt + 1).X) * _ second_factor Y = Y + (m_Points(pt).Y + m_Points(pt + 1).Y) * _ second_factor Next pt ' Divide by 6 times the polygon's area. polygon_area = PolygonArea X = X / 6 / polygon_area Y = Y / 6 / polygon_area ' If the values are negative, the polygon is ' oriented counterclockwise. Reverse the signs. If X &lt; 0 Then X = -X Y = -Y End If End Sub </code></pre> <p>For more info check this <a href="http://paulbourke.net/geometry/polyarea/" rel="noreferrer">website</a> or <a href="http://en.wikipedia.org/wiki/Centroid" rel="noreferrer">Wikipedia</a>.</p> <p>Hope it helps.</p> <p>Regards!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload