我应该编写计算三角形边界框的代码。边界框坐标应写入
triangle->bx, triangle->by, triangle->bw, triangle->bh
在哪里
bx, by is the upper left corner of the box
bw, bh is the width and height of the box
我应该将我的点视为坐标还是应该选择更多基于几何的解决方案?
我尝试找到每个坐标的最小值和最大值,但没有奏效。任何帮助将非常感激!
if (triangle->sx1 <= triangle->sx2 <= triangle->sx3)
{
triangle->bx = triangle->sx1;
}
else if (triangle->sx2 <= triangle->sx1 <= triangle->sx3)
{
triangle->bx = triangle->sx2;
}
else (triangle->bx = triangle->sx3);
if (triangle->sy1 <= triangle->sy2 <= triangle->sy3)
{
triangle->by = triangle->sy1;
}
else if (triangle->sy2 <= triangle->sy1 <= triangle->sy3)
{
triangle->by = triangle->sy2;
}
else (triangle->by = triangle->sy3);
if (triangle->sx1 >= triangle->sx2 >= triangle->sx3)
{
triangle->bw = triangle->sx1;
}
else if (triangle->sx2 >= triangle->sx1 >= triangle->sx3)
{
triangle->bw = triangle->sx2;
}
else (triangle->bw = triangle->sx3);
if (triangle->sy1 >= triangle->sy2 >= triangle->sy3)
{
triangle->bh = triangle->sy1;
}
else if (triangle->sy2 >= triangle->sy1 >= triangle->sy3)
{
triangle->bh = triangle->sy2;
}
else (triangle->bh = triangle->sy3);