Finding coordinates after canvas Rotation

前端 未结 2 443
死守一世寂寞
死守一世寂寞 2020-12-18 14:47

0 to 0,-70 by this :

ctx.strokeStyle = \"red\";
ctx.lineWidth = 2;
ctx.rotate(Math.PI/-10;);
ctx.beginPath();
ctx.moveTo(0,0); 
ctx.lineTo(0,-70);
ctx.stroke         


        
2条回答
  •  一向
    一向 (楼主)
    2020-12-18 15:23

    So you're asking "after I set a transform, how can I run points through that transform"?

    In that case, see HTML5 Canvas get transform matrix? . The question and answers are somewhat old, but seem up-to-date. I can't find anything in the current HTML5 spec that lets you access and use the transform matrix. (I see that it's theoretically accessable through context.currentTransform, but I don't see any functionality to let you use the matrix - you'd have to multiply your point through the matrix yourself, or fake it by creating a full SVGMatrix for your point vector.)

    The top answer shows a transform class you can use. Track your changes through that, and use their transformPoint function to get the point you want transformed to its endpoint.

提交回复
热议问题