我们如何绘制由Clipper库(c#)创建的偏移多边形(充气多边形)的解?使用DrawPolygons()方法?<



我下载了clipper库,它允许我膨胀一个多边形(偏移一个多边形)

"boundary_Points"是包含多边形所有顶点的点数组。下面是我使用的代码。不幸的是,在其他web示例中使用的命令" drawpolygon ()"并不是作为函数存在的。有什么方法可以访问这个命令或其他方法来绘制吗?挑战在于:Clipper库使用IntPoint类型,就我所知,它不能在GDI+中使用。由于

using Path = List<IntPoint>;
using Paths = List<List<IntPoint>>;

boundary_path.AddLines(boundary_Points);
Region boundary_region = new Region(boundary_path);
g.DrawPath(pen1, boundary_path);                
ClipperOffset co = new ClipperOffset();
Path boundary_point_list= new Path(); //contains all IntPoints of the polygon
co.AddPath(boundary_point_list, JoinType.jtRound, EndType.etClosedPolygon);
Paths solution = new Paths();   // 
co.Execute(ref solution, -7.0);
DrawPolygons(solution, 0x40808080);
g.FillPolygon(Brushes.Olive, boundary_Points);                

Clipper不提供开箱即用的绘图方法。您必须将IntPoint转换为您想要使用的绘图API手动绘制的任何格式。

我不使用c#,但这是我在代码中所做的,以便将IntPoint转换为c++中的基于浮点数的类型:

void scale_down_polypaths(const Paths &p_polypaths_in, Vector<Vector<Point2>> &p_polypaths_out) {
p_polypaths_out.clear();
for (int i = 0; i < p_polypaths_in.size(); ++i) {
const Path &polypath_in = p_polypaths_in[i];
Vector<Vector2> polypath_out;
for (int j = 0; j < polypath_in.size(); ++j) {
polypath_out.push_back(Point2(
static_cast<real_t>(polypath_in[j].X) / SCALE_FACTOR,
static_cast<real_t>(polypath_in[j].Y) / SCALE_FACTOR));
}
p_polypaths_out.push_back(polypath_out);
}
}

结果可以传递给绘图API,但同样,这取决于您使用的库类型。我没有GDI+的经验。

最新更新