|
// 假设你已经有一个CogRectangleAffine对象名为rectangleAffine
// 获取包围盒的中心点坐标
double centerX = rectangleAffine.CenterX;
double centerY = rectangleAffine.CenterY;
// 获取包围盒的宽度和高度
double width = rectangleAffine.SideXLength;
double height = rectangleAffine.SideYLength;
// 获取包围盒的角度(弧度)
double angle = rectangleAffine.Rotation;
// 计算四个顶点相对于中心点的偏移量
double offsetX = width / 2 * Math.Cos(angle) - height / 2 * Math.Sin(angle);
double offsetY = width / 2 * Math.Sin(angle) + height / 2 * Math.Cos(angle);
// 计算四个顶点的坐标
double[] vertexX = new double[4];
double[] vertexY = new double[4];
vertexX[0] = centerX + offsetX;
vertexY[0] = centerY + offsetY;
vertexX[1] = centerX - offsetX;
vertexY[1] = centerY - offsetY;
vertexX[2] = centerX - offsetX;
vertexY[2] = centerY - offsetY;
vertexX[3] = centerX + offsetX;
vertexY[3] = centerY + offsetY;
// 打印顶点坐标
for (int i = 0; i < 4; i++)
{
Console.WriteLine("顶点 {0}: ({1}, {2})", i+1, vertexX[i], vertexY[i]);
}
|
|