多边形边缘算法问题
我有二维多边形,它们的顶点位于局部多边形空间中。我正在尝试计算新的顶点,这些顶点将在多边形内部形成均匀长度的边。
目前为了计算边缘,我基本上缩小了原始顶点。对于每个多边形顶点,我计算负单位向量并将其乘以恒定的边长度因子。然后我将其添加到原始多边形顶点。
伪代码: <代码>
const float edgeLength = 0.5;
for each vertex v
vec2 n = -v.unit();
vec2 edgeVertex = v + n * edgeLength;
结果在正多边形上效果很好:
屏幕截图 1
但是,在其他多边形(例如矩形)上,边长不均匀:
截图 2
我尝试了很多不同的尝试,但到目前为止似乎没有任何效果,任何帮助都会不胜感激,谢谢! (请忽略多边形是以 3D 渲染的,实际的多边形数据是 2D)。
I have 2D polygons, with their vertices positioned in local polygon-space. I'm trying to calculate new vertices that would form a uniform length edge around the inside of the polygon.
Currently to calculate the edge, I'm basically shrinking the original vertices. For each polygon vertex I calculate the negated unit vector and multiply this by a constant edge length factor. Then I add this to the original polygon vertex.
Pseudocode:
const float edgeLength = 0.5; for each vertex v vec2 n = -v.unit(); vec2 edgeVertex = v + n * edgeLength;
The result works fine on regular polygons:
screenshot 1
However, on other polygons, such as rectangles, the edge lengths are not uniform:
screenshot 2
I've tried many different attempts, but nothing seems to work so far, any help would be greatly appreciated, thanks!
(Please ignore that the polygons are rendered in 3D, the actual polygon data is 2D).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
沿垂直于边缘的方向将每条边缘移动固定距离(如果边缘逆时针方向,则全部向左移动)。然后计算新边的交点——这些就是新的顶点。
Move each edge a fixed distance, in a direction perpendicular to the edge (all to the left, if the edges run counterclockwise). Then calculate the intersections of the new edges-- these are the new vertices.