2d transformation alone z-axis. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

2d transformation alone z-axis.

I need constant rotation but the square automatically shrinks, help me to fix it. https://code.sololearn.com/WsuEXwjcTjgG/?ref=app

8th Jun 2022, 5:20 PM
SAN
SAN - avatar
2 Answers
+ 4
Don't modify your reference points. You recalculate the rotation from the rotated frame. I suspect that rounding issues shrink your square... const Loop = () => { san.clearRect(0, 0, W, H); Angle += .01; q = [0,0,0,0,0,0,0,0] // transformation formula for(let i=0; i<p.length; i+=2) { q[i] = p[i]*Math.cos(Angle) - p[i+1]*Math.sin(Angle); // x axis q[i+1] = p[i]*Math.sin(Angle) + p[i+1]*Math.cos(Angle); // y axis } // draw points san.beginPath(); san.lineWidth=5; for(let i=0; i<p.length; i+=2) { san.lineTo(300 + q[i], 300+ q[i+1]) } san.closePath(); san.stroke(); webkitRequestAnimationFrame(Loop); }
8th Jun 2022, 6:08 PM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 4
Thank you so much :)
9th Jun 2022, 1:54 AM
SAN
SAN - avatar