rt-graphic-component/components/common/CommonGraphics.js
joylink_zhaoerwei 0619184b9b 打包测试
2024-01-15 18:11:29 +08:00

51 lines
1.6 KiB
JavaScript

import { calculateMirrorPoint } from 'jl-graphic';
/**
*
* @param polygon
* @param x 箭头顶点x坐标
* @param y 箭头顶点y坐标
* @param length 箭头长度
* @param radius 箭头三角半径
* @param lineWidth 箭头线宽
* @param mirror 是否镜像翻转 (基于箭头顶点)
*/
function drawArrow(polygon, x, y, length, radius, lineWidth, mirror) {
const trianglAcme = { x, y };
let triangleP1 = {
x: x - radius - Math.sin(Math.PI / 6),
y: y + Math.cos(Math.PI / 6) * radius,
};
let triangleP2 = {
x: x - radius - Math.sin(Math.PI / 6),
y: y - Math.cos(Math.PI / 6) * radius,
};
let lineP1 = {
x: x - radius - Math.sin(Math.PI / 6),
y: y + lineWidth / 2,
};
let lineP2 = {
x: x - length,
y: y + lineWidth / 2,
};
let lineP3 = {
x: x - length,
y: y - lineWidth / 2,
};
let lineP4 = {
x: x - radius - Math.sin(Math.PI / 6),
y: y - lineWidth / 2,
};
if (mirror) {
triangleP1 = calculateMirrorPoint(trianglAcme, triangleP1);
triangleP2 = calculateMirrorPoint(trianglAcme, triangleP2);
lineP1 = calculateMirrorPoint(trianglAcme, lineP1);
lineP2 = calculateMirrorPoint(trianglAcme, lineP2);
lineP3 = calculateMirrorPoint(trianglAcme, lineP3);
lineP4 = calculateMirrorPoint(trianglAcme, lineP4);
}
polygon.drawPolygon(trianglAcme.x, trianglAcme.y, triangleP1.x, triangleP1.y, lineP1.x, lineP1.y, lineP2.x, lineP2.y, lineP3.x, lineP3.y, lineP4.x, lineP4.y, triangleP2.x, triangleP2.y);
}
export { drawArrow };