Tag Archives: lines

Draw “marching ants” dashed lines in C#

The example Draw dashed lines that are visible on any background in C# shows how to draw lines that are visible above any backgrounds. If the background is very cluttered, however, it may still be somewhat hard to see the … Continue reading

Posted in animation, drawing, graphics | Tagged , , , , , , , , , , , , , | 4 Comments

Draw dashed lines that are visible on any background in C#

This example shows how to draw dashed lines that are visible on any background. Sometimes it’s hard to draw lines that are visible on top of a photo or other complicated background. For example, when the user is clicking and … Continue reading

Posted in drawing, graphics | Tagged , , , , , , , , , , , | 1 Comment

Find the shortest distance between a point and a line segment in C#

This example treats the segment as parameterized vector where the parameter t varies from 0 to 1. It finds the value of t that minimizes the distance from the point to the line. If t is between 0.0 and 1.0, … Continue reading

Posted in algorithms, geometry, graphics, mathematics | Tagged , , , , , , , , , , , , , , | 21 Comments

Fill an ellipse with random lines in C#

As the title implies, this example draws an ellipse filled with random lines. It cannot simply draw the ellipse in the form’s Paint event handler, however. That would make the program generate a new set of random lines every time … Continue reading

Posted in drawing, graphics | Tagged , , , , , , , , , , | Leave a comment

Draw round circles in scaled coordinate systems in C#

In other posts I explain how you can use transformations to draw objects in a coordinate system other than the one provided “natively” by a PictureBox, Bitmap, and other objects that support drawing. Basically a transformation (represented by a Matrix … Continue reading

Posted in drawing, graphics, mathematics | Tagged , , , , , , , , , , , , , , , | Leave a comment

Draw rainbow compound lines in WPF and C#

The post Make compound lines in WPF and C# shows how to make compound lines, lines that are striped lengthwise. Once you know how to do that, it’s easy to make rainbow compound lines. The following code shows how this … Continue reading

Posted in algorithms, drawing, graphics, mathematics | Tagged , , , , , , , , , , , , , , , , , , , | Leave a comment

Make compound lines in WPF and C#

In order to draw an outlined path, the post Draw an outlined path in WPF and C# explained how to find the left and right edge points for a path. This post explains how to use those points to draw … Continue reading

Posted in algorithms, drawing, graphics, mathematics | Tagged , , , , , , , , , , , , , , , , , , | Leave a comment

Draw an outlined path in WPF and C#

Most of the techniques needed to draw an outlined path are included in those you need to draw compound lines. For the basic idea behind compound lines and a technique that lets you draw symmetric compound lines relatively easily, see … Continue reading

Posted in algorithms, drawing, graphics, mathematics | Tagged , , , , , , , , , , , , , , , , , | 3 Comments

Draw symmetric compound lines in WPF and C#

I’ve often said that WPF’s unofficial slogan should be, “Twice as flexible and only 10 times as hard.” Drawing compound lines is one of the few places where WPF isn’t twice as flexible. A compound line is one that is … Continue reading

Posted in algorithms, drawing, graphics | Tagged , , , , , , , , , , | Leave a comment

Draw lines with end caps in C#

The Pen class’s StartCap and EndCap properties determine how a line draws its end caps. This example uses the following code to draw samples of the predefined end caps. private void Form1_Paint(object sender, PaintEventArgs e) { e.Graphics.Clear(BackColor); e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; … Continue reading

Posted in drawing, graphics | Tagged , , , , , , , , , , | Leave a comment