[英]Get rotated rectangle points from x, y, width, height and rotation
對於尋找這個的其他人。 這是這樣做的功能。
x,y,高度和寬度如下圖所示。 ang是x,y點與Y軸之間的角度。 如果只想在x,y點和X軸之間進行操作: ang = 90 - ang
然后將其發送給函數
isDeg只是您是以弧度還是度數發送ang。
function getRectFourPoints(x,y, width, height, ang, isDeg = false) { if(isDeg) ang = ang * (Math.PI / 180) const points = {first: {x,y}} const sinAng = Math.sin(ang) const cosAng = Math.cos(ang) let upDiff = sinAng * width let sideDiff = cosAng * width const sec = {x: x + sideDiff, y: y + upDiff} points.sec = sec upDiff = cosAng * height sideDiff = sinAng * height points.third = {x: x + sideDiff, y: y - upDiff} const fourth = {x: sec.x + sideDiff, y: sec.y - upDiff} points.fourth = fourth return points }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.