(参考插图:https://i.stack.imgur.com/Wsge0.png)
代码示例 https://jsfiddle.net/waaentz/htrqdwjp/9/
const width = 1000;
const height = 100;
const canvas = document.createElement("canvas");
const stage = new createjs.Stage(canvas);
const img = new Image();
const bitmap = new createjs.Bitmap(img);
const baseGrid = new createjs.Shape();
const angle = 45; // Is dynamic
const magicScaleFormular = 1.39 // Find scale based on height and angle
img.src = getBase64();
img.addEventListener("load",()=>{
stage.addChild(baseGrid,bitmap);
Object.assign(canvas,{width,height});
bitmap.regX = (img.width / 2);
bitmap.regY = img.height;
bitmap.y = height;
bitmap.rotation = angle;
bitmap.scaleY = magicScaleFormular; // <-- scale to match top line
baseGrid.graphics
.beginStroke("red")
.setStrokeStyle(4)
.moveTo(0,0)
.lineTo(width,0)
.moveTo(0,height)
.lineTo(width,height)
stage.update();
document.body.append(canvas);
});
我有一个100像素高的图像,当根据其角度旋转时,该图像需要增大尺寸以匹配顶部y线。当前第一行是y0,但可以是任何电线。
Math.sin和Math.cos的大小似乎发生了奇怪的变化,因此我不再尝试为此使用它们。
当图像旋转90度时,理论上它将增长到无限大小。这种数学巫术超出了我的思维能力,我希望这里有个聪明的人能对我表示怜悯,让我了解这个数学秘密。