简体   繁体   English

在贝塞尔曲线上找到点。 (GDI +)

[英]Find the points on a bezier curve. (GDI+)

Can you please help me to accomplish this using c#. 您能否帮助我使用c#完成此操作。

I have a GDI+ call as below: 我有一个GDI +电话,如下所示:

graphics.FillPie(Brushes.White, _
                 new Rectangle(0, 0, 400, 150), 0 - 90, 77.783651160272726f);

graphics.DrawArc(new System.Drawing.Pen(Brushes.Black, 2), _
                 new RectangleF(0, 0, 400, 150), 0 - 90, 77.783651160272726f);

My requirement is to find all the points along the bezier curve/shape(pie, arc). 我的要求是找到沿贝塞尔曲线/形状(饼形,弧形)的所有点。

ie, I need to redraw the shape in my method, which accepts only a point array . 即,我需要在我的方法中重绘形状,该方法仅接受点数组 I have only the rectangle co-ordinates, start angle and sweep angle with me. 我只有矩形坐标,起始角和后掠角。 Can anyone let me know if there is any inbuild method in .net for calculating this or is there any easy method to find this one. 谁能让我知道.net中是否有用于计算此内容的内置方法,或者是否有找到该方法的简便方法。

Please let me know if you need any other informations. 如果您需要其他任何信息,请告诉我。 Kindly help me as this is very critical for me as I am not a genious in Math. 请帮助我,因为这对我来说很关键,因为我在数学上不是很聪明。

Thanks in advance. 提前致谢。

Regards, James 问候,詹姆斯

I have done the math and created a function called BezierCoordinates in the below given article in code project. 我已经完成了数学运算,并在下面代码项目中的给定文章中创建了一个名为BezierCoordinates的函数。

BezierCurve 贝兹曲线

Its a solution done in C#, Displayed in Silverlight. 它是在C#中完成的解决方案,在Silverlight中显示。

将圆弧/曲线添加到GraphicsPath对象,使用Flatten方法将路径中的Bezier曲线近似为线段,并使用PathPoints属性获取点的数组。

Do you really have to represent this as an array of points? 您是否真的必须将其表示为点数组?

If you can be flexible on the signature of your method, and instead of Point[] accept a GraphicsPath , then you can represent this curve in C# by compining the two parts. 如果您可以灵活地签名方法,并且可以代替Point[]接受GraphicsPath ,则可以通过组合两个部分来用C#表示此曲线。

EDIT: Adding example 编辑:添加示例

For example, you can create a GraphicsPath like this: 例如,您可以创建一个GraphicsPath如下所示:

GraphicsPath path = new GraphicsPath();
path.AddPie(new Rectangle(0, 0, 400, 150), -90, 77.78f);
path.AddArc(new Rectangle(0, 0, 400, 150), -90, 77.78f);

You can later use it to draw graphics using the Graphics.DrawPath method, or access the graphics path data through the GraphicsPath.PathPoints , GraphicsPath.PathTypes and GraphicsPath.PointCount properties. 您以后可以使用它通过Graphics.DrawPath方法绘制图形,或者通过GraphicsPath.PathPointsGraphicsPath.PathTypesGraphicsPath.PointCount属性访问图形路径数据。

You'll need some math, but fortunately nothing crazy. 您将需要一些数学运算,但是幸运的是没有什么疯狂的。 This site explains how to draw a circle by calculating points on it: 该站点介绍了如何通过计算圆点来绘制圆:

http://www.nsbasic.com/palm/info/technotes/TN25a.htm http://www.nsbasic.com/palm/info/technotes/TN25a.htm

It's not in C# but should give you an idea of how it works. 它不在C#中,但应该让您了解它的工作原理。 Math.Sin() and Math.Cos() are .NET's sin and cos methods. Math.Sin()Math.Cos()是.NET的sin和cos方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM