Find the points on a bezier curve. (GDI+)
Can you please help me to accomplish this using c#.
I have a GDI+ call as below:
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).
i.e, I need to redraw the shape in my method, which accepts only a point array. I have o开发者_高级运维nly 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.
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.
BezierCurve
Its a solution done in C#, Displayed in Silverlight.
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.
EDIT: Adding example
For example, you can create a GraphicsPath
like this:
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.
Add your arc/curve to a GraphicsPath object, use the Flatten method to approximate the Bezier curves in the path as line segments, and use the PathPoints property to get the array of points.
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
It's not in C# but should give you an idea of how it works. Math.Sin()
and Math.Cos()
are .NET's sin and cos methods.
精彩评论