Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This one's tricky because irregular polygons have no defined center. Since your polygons are (in the case of rectangles) guaranteed to be convex, you can probably find the corners of the polygon that comprises the collision (which can include corners of the original shapes or intersections of the edges) and average them to get ... something. It will probably be vaguely close to where you would expect the "center" to be, and for regular polygons it would probably match exactly, but whether it would mean anything mathematically is a bit of a different story.</p> <p>I've been fiddling mathematically and come up with the following, which solves the smoothness problem when points appear and disappear (as can happen when the movement of a hitbox causes a rectangle to become a triangle or vice versa). Without this bit of extra, adding and removing corners will cause the centroid to jump.</p> <p><a href="http://fooplot.com/#W3sidHlwZSI6MywiZXEiOltbIi0xIiwiLTIiXSxbIjEiLCItMS41Il0sWyItMS43NSIsIjEiXSxbIi4yNSIsIjEuNSJdXSwiY29sb3IiOiIjRkYwMDAwIn0seyJ0eXBlIjozLCJlcSI6W1siLTEiLCIwIl0sWyIxIiwiMiJdLFsiMSIsIi0yIl0sWyIzIiwiMCJdXSwiY29sb3IiOiIjMDAzM0ZGIn0seyJ0eXBlIjozLCJlcSI6W1siLjMiLCIxLjMiXSxbIi0xIiwiMCJdLFsiMC42IiwiLTEuNiJdLFsiMSIsIi0xLjUiXV0sImNvbG9yIjoiIzA5RkYwMCJ9LHsidHlwZSI6MywiZXEiOltbIi4yMjUiLCItLjQ1Il0sWyIuMjA3NyIsIi0uNDczMCJdXSwiY29sb3IiOiIjRkYwMEVBIn0seyJ0eXBlIjoxMDAwLCJ3aW5kb3ciOlsiLTMuNTQwOTAzMjY0MjU1OTk4IiwiMy4yNzQ4NDA3MzU3NDM5OTkiLCItMi42MDg4NjIzMzA4Nzk5OTg3IiwiMS41ODU0NDE2NjkxMTk5OTg2Il19XQ--" rel="nofollow">Here, take this fooplot.</a></p> <p>The plot illustrates 2 rectangles, R and B (for Red and Blue). The intersection sweeps out an area G (for Green). The Unweighted and Weighted Centers (both Purple) are calculated via the following methods:</p> <pre><code>(0.225, -0.45): Average of corners of G (0.2077, -0.473): Average of weighted corners of G </code></pre> <p>A weighted corner of a polygon is defined as the coordinates of the corner, weighted by the sin of the angle of the corner.</p> <p>This polygon has two 90 degree angles, one 59.03 degree angle, and one 120.96 degree angle. (Both of the non-right angles have the same sine, sin(Ɵ) = 0.8574929...</p> <p>The coordinates of the weighted center are thus:</p> <pre><code>( (sin(Ɵ) * (0.3 + 0.6) + 1 - 1) / (2 + 2 * sin(Ɵ)), // x (sin(Ɵ) * (1.3 - 1.6) + 0 - 1.5) / (2 + 2 * sin(Ɵ)) ) // y = (0.2077, -0.473) </code></pre> <p>With the provided example, the difference isn't very noticeable, but if the 4gon were much closer to a 3gon, there would be a significant deviation.</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. 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.
 

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