Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Propaply you want calclulate new border vertex list (easy fill example with triangle strip with originals). If you use constant border width and convex polygon its just:</p> <p>B_new = B - (BtoA.normalised() + BtoC.normalised()).normalised() * width;</p> <p><img src="https://i.stack.imgur.com/CtBc4.png" alt="enter image description here"></p> <p>If not then it can go more complicated, there is my old but pretty universal solution: </p> <p><code><br> //Helper function. To working right, need that v1 is before v2 in vetex list and vertexes are going to (anti???) cloclwise! float vectorAngle(Vector2 v1, Vector2 v2){</p> <pre><code> float alfa; if (!v1.isNormalised()) v1.normalise(); if (!v2.isNormalised()) v2.normalise(); alfa = v1.dotProduct(v2); float help = v1.x; v1.x = v1.y; v1.y = -help; float angle = Math::ACos(alfa); if (v1.dotProduct(v2) &lt; 0){ angle = -angle; } return angle; } //Normally dont use directly this! Vector2 calculateBorderPoint(Vector2 vec1, Vector2 vec2, float width1, float width2){ vec1.normalise(); vec2.normalise(); float cos = vec1.dotProduct(vec2); //Calculates actually cosini of two (normalised) vectors (remember math lessons) float csc = 1.0f / Math::sqrt(1.0f-cos*cos); //Calculates cosecant of angle, This return NaN if angle is 180!!! //And rest of the magic Vector2 difrence = (vec1 * csc * width2) + (vec2 * csc * width1); //If you use just convex polygons (all angles &lt; 180, = 180 not allowed in this case) just return value, and if not you need some more magic. //Both of next things need ordered vertex lists! //Output vector is always to in side of angle, so if this angle is. if (Math::vectorAngle(vec1, vec2) &gt; 180.0f) //Note that this kind of function can know is your function can know that angle is over 180 ONLY if you use ordered vertexes (all vertexes goes always (anti???) cloclwise!) difrence = -difrence; //Ok and if angle was 180... //Note that this can fix your situation ONLY if you use ordered vertexes (all vertexes goes always (anti???) cloclwise!) if (difrence.isNaN()){ float width = (width1 + width2) / 2.0; //If angle is 180 and border widths are difrent, you cannot get perfect answer ;) difrence = vec1 * width; //Just turn vector -90 degrees float swapHelp = difrence.y difrence.y = -difrence.x; difrence.x = swapHelp; } //If you don't want output to be inside of old polygon but outside, just: "return -difrence;" return difrence; } //Use this =) Vector2 calculateBorderPoint(Vector2 A, Vector2 B, Vector2 C, float widthA, float widthB){ return B + calculateBorderPoint(A-B, C-B, widthA, widthB); } </code></pre> <p></code></p>
 

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