Note that there are some explanatory texts on larger screens.

plurals
  1. POAbout: Rectangle rotation and fitting
    primarykey
    data
    text
    <p>after a hard work, my brain turns out of service.. (it is 11:40 P.M. in Turkey)</p> <p>I am doing a rotation job.:</p> <p>variables:</p> <pre><code>_cx = horizontal center of rect _cy = vertical center of rect _cos = cos value of current angle _sin = sin value of current angle to rotating any point in this rect : function getx(x, y) { return _cx + _cos * (x - _cx) - _sin * (y - _cy); } function gety(x, y) { return _cy + _sin * (x - _cx) + _cos * (y - _cy); } </code></pre> <p>I am trying to do resize given rectangle before rotation process to maximum size what fitted in original bounds.. how could I do?</p> <p>thanks your advance</p> <p><strong>EDIT : Igor Krivokon's solution</strong></p> <p>The problem is solved by Igor Krivokon, and here is the modified version of that solution what works for every angle value</p> <pre><code>var h1:Number, h2:Number, hh:Number, ww:Number, degt:Number, d2r:Number, r2d:Number, deg:Number, sint:Number, cost:Number; //@angle = given angle in radians //@r is source/target rectangle //@d2r is static PI / 180 constant for degree -&gt; radian conversation //@r2d is static 180 / PI constant for radian -&gt; degree conversation d2r = 0.017453292519943295769236907683141; r2d = 57.295779513082320876798154814105; deg = Math.abs(angle * r2d) % 360; if(deg &lt; 91) { degt = angle; }else if(deg &lt; 181){ degt = (180 - deg) * d2r; }else if(deg &lt; 271){ degt = (deg - 180) * d2r; }else{ degt = (360 - deg) * d2r; } sint = Math.sin(degt); cost = Math.cos(degt); h1 = r.height * r.height / (r.width * sint + r.height * cost); h2 = r.height * r.width / (r.width * cost + r.height * sint); hh = Math.min(h1, h2); ww = hh * r.width / r.height; r.x = (r.width - ww) * .5; r.y = (r.height - hh) * .5; r.height = hh; r.width = ww; </code></pre> <p>Thanks</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.
 

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