draw curved line from point to point - DOTNET
This is a discussion on draw curved line from point to point - DOTNET ; Dear NG,
I want to draw a curved line like here: http://www.dusch-westermaier.de/img/wave.gif
from a point A to a point B.
Do you have any idea how to handle this in C#?
Thank you very much,
Rudi...
-
draw curved line from point to point
Dear NG,
I want to draw a curved line like here: http://www.dusch-westermaier.de/img/wave.gif
from a point A to a point B.
Do you have any idea how to handle this in C#?
Thank you very much,
Rudi
-
Re: draw curved line from point to point
On 27 Jun., 23:40, Lakesider <i...@rudolfball.com> wrote:
> Dear NG,
>
> I want to draw a curved line like here:http://www.dusch-westermaier.de/img/wave.gif
> from a point A to a point B.
>
> Do you have any idea how to handle this in C#?
>
> Thank you very much,
>
> Rudi
I found this: http://www.codedblog.com/2007/09/17/...forms-textbox/
but it only draws a horizontal line ... not from A to B somewhere on
the screen.
Any ideas ... ?
Thank you
Rudi
-
Re: draw curved line from point to point
You can draw a curve with multiple points but you must calculate the points.
I suggest that the easiest way would be to plot the points along a
horizontal line and then transfrom those points into position.
Take the hypotenuse of the right triangle defined by A and B, fill a set of
points to the rquired wavyness and then transform them into place.
Something like the code after my signature.
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
// draw line from (10,10) to (150,75)
Point A = new Point(10, 10);
Point B = new Point(150, 75);
int sidea=B.X-A.X;
int sideb=B.Y-A.Y;
float hypot = (float)Math.Sqrt((sidea * sidea) + (sideb * sideb));
float angle = (float)Math.Atan2(sideb, sidea); // have to adjust this for
quadrant...
Point[] points = new Point[11];
//fill the point array
for (int c=0, n=10; c <= 10; n=-n, c++)
{
points[c] = new Point((int)(hypot/10*c),n);
}
//plot a and b to check the positions...
e.Graphics.DrawLine(Pens.Black, A.X, 0, A.X, 1000);
e.Graphics.DrawLine(Pens.Black, 0, A.Y, 1000, A.Y);
e.Graphics.DrawLine(Pens.Black, B.X, 0, B.X, 1000);
e.Graphics.DrawLine(Pens.Black, 0, B.Y, 1000, B.Y);
Matrix mx = new Matrix();
mx.Rotate((float)(angle/Math.PI*180));
mx.Translate(A.X, A.Y,MatrixOrder.Append);
//transform the points...
mx.TransformPoints(points);
// draw the curve
Pen p=new Pen(Color.Red,5);
e.Graphics.DrawCurve(p, points);
p.Dispose();
base.OnPaint(e);
"Lakesider" <info@rudolfball.com> wrote in message
news:f8b396b2-4027-4d0e-8cd2-8a346b3ba465@e53g2000hsa.googlegroups.com...
> Dear NG,
>
> I want to draw a curved line like here:
> http://www.dusch-westermaier.de/img/wave.gif
> from a point A to a point B.
>
> Do you have any idea how to handle this in C#?
>
> Thank you very much,
>
> Rudi
-
Re: draw curved line from point to point
"Lakesider" <info@rudolfball.com> skrev i meddelandet
news:f8b396b2-4027-4d0e-8cd2-8a346b3ba465@e53g2000hsa.googlegroups.com...
> Dear NG,
>
> I want to draw a curved line like here:
> http://www.dusch-westermaier.de/img/wave.gif
> from a point A to a point B.
>
> Do you have any idea how to handle this in C#?
>
> Thank you very much,
>
> Rudi
Search for Bezier curves on Google, you will find numerous examples in code
of what Bob Powell wrote.
E.g. http://www.codeproject.com/KB/recipes/BezirCurves.aspx
-
Re: draw curved line from point to point
Why not just calculate points using Math.Sin() function (or Cos if you
wish). Use this function: y = k * Sin(x). k is a constant and the lower the
k the more flat curve you get. Start with k = 1 and decrease it by 0.1 to
see results. Then create an array of points and calculate y for each x,
incrementing x by some dx untill you reach the right border. Then, draw a
polyline on a graphics using this point array. Try to use the largest number
possible for dx to decrease the amount of points while still having the
best-looking curve.
regards
Tomaz
"Lakesider" <info@rudolfball.com> wrote in message
news:f8b396b2-4027-4d0e-8cd2-8a346b3ba465@e53g2000hsa.googlegroups.com...
> Dear NG,
>
> I want to draw a curved line like here:
> http://www.dusch-westermaier.de/img/wave.gif
> from a point A to a point B.
>
> Do you have any idea how to handle this in C#?
>
> Thank you very much,
>
> Rudi