Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try the following: split the original rectangle and this figure with 2 diagonals. Their crossing is (k, l). You have 4 distorted triangles (ab-cd-kl, cd-ef-kl, ef-gh-kl, gh-ab-kl) and the point xy is in one of them.</p> <p>(4 triangles are better than 2, since the distortion doesn't depend on the diagonal chosen)</p> <p>You need to find in which triangle point XY is. To do that you need only 2 checks:</p> <ol> <li>Check if it's in ab-cd-ef. If true, go on with ab-cd-ef, (in your case it's not, so we proceed with cd-ef-gh).</li> <li>We don't check cd-ef-gh, but already check a half of it: cd-gh-kl. The point is there. (Otherwise it would have been ef-gh-kl)</li> </ol> <p>Here's <a href="http://alienryderflex.com/polygon/" rel="nofollow noreferrer">an excellent algorythm</a> to check if a point is in a polygon, using only it's points.</p> <p>Now you need only to map the point to the original triangle cd-gh-kl. The point xy is a linear combination of the 3 points:</p> <pre><code>x = c * a1 + g * a2 + k * (1 - a1 - a2) y = d * a1 + h * a2 + l * (1 - a1 - a2) a1 + a2 &lt;= 1 </code></pre> <p>2 variables (a1, a2) with 2 equations. I guess you can derive the solution formulae on your own.</p> <p>Then you just make a linear combinations of a1&amp;a2 with the corresponding points' co-ordinates in the original rectangle. In this case with W (width) and H (height) it's</p> <pre><code>X = width * a1 + width * a2 + width / 2 * (1 - a1 - a2) Y = 0 * a1 + height * a2 + height / 2 * (1 - a1 - a2) </code></pre>
 

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