绘制形状
This commit is contained in:
@@ -39,4 +39,57 @@ export async function getObjectsBoundingBox(objects = []) {
|
||||
width: box2.x - box1.x,
|
||||
height: box2.y - box1.y,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** 获取五角星数组 */
|
||||
export function getStarArr(width = 0, height = 0) {
|
||||
const arr = [
|
||||
{ x: 0, y: -0.5 }, // 顶点0 (上)
|
||||
{ x: 0.15, y: -0.15 }, // 顶点1 (内)
|
||||
{ x: 0.50, y: -0.15 }, // 顶点2 (右上外)
|
||||
{ x: 0.20, y: 0.10 }, // 顶点3 (内)
|
||||
{ x: 0.30, y: 0.50 }, // 顶点4 (右下外)
|
||||
{ x: 0.0, y: 0.25 }, // 顶点5 (内)
|
||||
{ x: -0.30, y: 0.50 }, // 顶点6 (左下外)
|
||||
{ x: -0.20, y: 0.10 }, // 顶点7 (内)
|
||||
{ x: -0.50, y: -0.15 }, // 顶点8 (左上外)
|
||||
{ x: -0.15, y: -0.15 } // 顶点9 (内)
|
||||
]
|
||||
return arr.map(item => ({
|
||||
x: item.x * width,
|
||||
y: item.y * height,
|
||||
}))
|
||||
}
|
||||
/** 获取箭头路径 */
|
||||
export function getArrowPath(width = 0, height = 0) {
|
||||
const arr = [
|
||||
["M", 0, height / 2],
|
||||
["L", width, height / 2],
|
||||
["M", width - 8, 0],
|
||||
["L", width, height / 2],
|
||||
["L", width - 8, height],
|
||||
]
|
||||
var path = ""
|
||||
arr.forEach(item => {
|
||||
path += item.join(" ") + " "
|
||||
})
|
||||
return path
|
||||
}
|
||||
|
||||
/** 计算两点之间的距离 */
|
||||
export function distance(x1, y1, x2, y2) {
|
||||
const dx = x2 - x1;
|
||||
const dy = y2 - y1;
|
||||
return Math.sqrt(dx * dx + dy * dy);
|
||||
}
|
||||
/** 计算两点之间的角度(角度) */
|
||||
export function angleBetweenPointsDegrees(x1, y1, x2, y2) {
|
||||
const dx = x2 - x1;
|
||||
const dy = y2 - y1;
|
||||
|
||||
// 计算弧度并转换为角度
|
||||
const rad = Math.atan2(dy, dx);
|
||||
const deg = rad * 180 / Math.PI;
|
||||
|
||||
return deg;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user