advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Partners & Affiliates
advertisement
advertisement
Tip of the Day
Rate this item | 0 users have rated this item.
Tip formerly from VB2TheMax
Expertise: Intermediate
Language: VB.NET
March 30, 2002
Drawing Cardinal splines
GDI+ supports two different forms of a complex curve that can't be represented as an arc of a circle or an ellipse: a cardinal spline and a Bézier spline. A cardinal spline is the curve that you would create by taking a piece of flexible material-such as a thin stripe of iron or wood-and making it pass through a given set of fixed points on the X-Y plane. Unless the material you're using is infinitely flexible (as it would be a string of rope or rubber), the path drawn by the material would be a curve that doesn't create any sharp angles at the connecting points. Depending on the degree of flexibility (also known as tension) of the material used, a given set of points can generate different curves. The default tension is 0.5. The following code snippet draws five cardinal splines, with a tension that goes from 0 (which corresponds to a material with infinite flexibility, which therefore draws straight lines) to 2:

' This statement assumes that you have imported the System.Drawing namespace

' This code should run inside a Windows Form class
Dim gr As Graphics = Me.CreateGraphics
Dim points() As Point = {New Point(100, 100), New Point(200, 200), _
    New Point(250, 30), New Point(350, 100)}
Dim tension As Single
For tension = 0 To 2 Step 0.5
    gr.DrawCurve(Pens.Blue, points, tension)
Next
gr.Dispose
You can also draw a closed cardinal spline by using the DrawClosedCurve method, which takes an array of Point objects.
Francesco Balena
If you have a hot tip and we publish it, we'll pay you. However, due to accounting overhead we no longer pay $10 for a single tip submission. You must accumulate 10 acceptable tips to receive payment. Be sure to include a clear explanation of what the technique does and why it's useful. If it includes code, limit it to 20 lines if possible. Submit your tip here.
Please rate this item (5=best)
 1  2  3  4  5
advertisement
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs