我需要像素化/從封閉的2D多邊形獲得點。不勾勒,但用「像素」體素填充,以檢索它們的位置作爲點。 現在我有用於線柵格的C#代碼,有沒有類似於多邊形的方法?Bresenhams多邊形C#
0
A
回答
0
只需使用DrawLine()
繪製一個多邊形。沒有繪製多邊形的具體算法。
void DrawPoly(IEnumerable<Point> points)
{
endpoints = points.Skip(1).Concat(new []{points.First()});
pairs = points.Zip(endpoints, Tuple.Create);
for(var pair in pairs)
{
DrawLine(pair.Item1, pair.Item2);
}
}
void DrawLine(Point p1, Point p2)
{
// Your Bresenham code here
}
據編輯,你要填充的多邊形。如果您想手動執行此操作,請嘗試使用these之一。
聽起來好像你想要一個包含多邊形的所有座標的大列表。有可能有更好的方法來解決潛在的問題。但是,您有兩種選擇:
- 在繪製每個點時存儲它。這要求您重寫上述算法。
使用現有庫繪製多邊形。然後,把得到的圖像和附加座標圖像矩陣,它壓扁成一維列表,然後過濾掉非黑值:
/* (0,0), (0,1), ..., (w,h) */ grid = Enumerable.Range(0, width) .SelectMany(x => Enumerable.Range(0, height) .Select(y => new Point(x, y))); flattened = image.SelectMany(p => p) .Zip(grid, (a,b) => new {PixelValue = a, Coordinate = b}); filledPoints = flattened.Where(p => p.PixelValue == 0) .Select(p => p.Coordinate);
0
如何我這件事情與矩陣連接存儲填充像素?
public static List<Tuple<int, int>> PixelizePolygon(PaintEventArgs e)
{
List<Tuple<int,int>> pixels = new List<Tuple<int, int>>();
// Create solid brush.
SolidBrush blueBrush = new SolidBrush(Color.Blue);
// Create points that define polygon.
PointF point1 = new PointF(50.0F, 50.0F);
PointF point2 = new PointF(100.0F, 25.0F);
PointF point3 = new PointF(200.0F, 5.0F);
PointF point4 = new PointF(250.0F, 50.0F);
PointF point5 = new PointF(300.0F, 100.0F);
PointF point6 = new PointF(350.0F, 200.0F);
PointF point7 = new PointF(250.0F, 250.0F);
PointF[] curvePoints = { point1, point2, point3, point4, point5, point6, point7 };
// Define fill mode.
FillMode newFillMode = FillMode.Winding;
// Fill polygon to screen.
e.Graphics.FillPolygon(blueBrush, curvePoints, newFillMode);
return pixels;
}
相關問題
- 1. 多邊形三角形c#
- 2. 多邊形在C++
- 3. GET中心多邊形C#
- 4. 多邊形在Objective-C
- 5. 多邊形C++的凸性?
- 6. C#多邊形掩碼?
- 7. 編輯多邊形多邊形的多邊形路徑事件
- 8. C#填充多邊形(三角形)
- 9. 多邊形組中的STConvexHull()多邊形
- 10. 從多邊形構造多邊形
- 11. 多邊形到多邊形碰撞libgdx
- 12. 將多邊形轉換爲多邊形
- 13. 多邊形周邊
- 14. 處理多邊形的多邊形算法,處理跨邊界的多邊形
- 15. 是多邊形
- 16. 多邊形
- 17. 與多邊形
- 18. 由頂點數組多邊形獲取多邊形的邊
- 19. 從具有共線邊的多邊形中提取多邊形
- 20. 使用多邊形中的點填充C中的多邊形算法
- 21. 多邊形的邊界框
- 22. 多邊形融合邊
- 23. 多邊形邊上的點
- 24. C# - 隨機旋轉多邊形
- 25. C++ 2D多邊形碰撞檢測
- 26. C#填寫多邊形的一面
- 27. 面積的多邊形的WinRT XAML C#
- 28. 檢查多邊形在C++中
- 29. c中的多邊形深度排序#
- 30. C#WPF - 使多邊形封裝文本
也許我的問題是不準確的,我正在尋找如何用像素填充多邊形並檢索它們的位置。像體素化一樣。 –
聽起來像是在尋找[多邊形填充算法](https://www.tutorialspoint.com/computer_graphics/polygon_filling_algorithm.htm)。那裏列出了一些。如果要提取所有點的列表,可以:1.在繪製點時存儲點,或2.將座標附加到圖像矩陣,將其平鋪到一維列表中,然後執行一個'.Where (p => p.PixelValue == 0)'。 –
如果我有繪製多邊形並填充它的簡單函數,如何附加圖像矩陣?見下面我的功能 –