
如图 我应该怎么算出红色框的长度和高度 ,其中是一个长方形,他在画布中,还需要获取红色框的左上角的xy轴信息,以及右下角的xy轴的信息,已知的是 其中盒子的宽高 和x1和y1的轴坐标,其中两个不知道

如图 我应该怎么算出红色框的长度和高度 ,其中是一个长方形,他在画布中,还需要获取红色框的左上角的xy轴信息,以及右下角的xy轴的信息,已知的是 其中盒子的宽高 和x1和y1的轴坐标,其中两个不知道
function getRebBoxWidthAndHeight(X1: { x: number, y: number }, Y1: { x: number, y: number }, boxW: number, boxH: number) {
let height = Math.sqrt(Math.pow(boxH, 2) + Math.pow(boxW, 2));
let width = X1.x - Y1.x;
let cosDeg = boxW / height;
let Y1BottomHeight = boxW * cosDeg;
let rightBottom = {
x: X1.x,
y: Y1.y+Y1BottomHeight
};
let leftTop = {
x: Y1.x,
y: rightBottom.y-height
};
return {
width,
height,
rightBottom,
leftTop
}
}