Tag Archives: polygon

Clip a line segment to a polygon in C#

This example finds the pieces of a line segment that lie inside and outside of a polygon. It draws the parts of the segment that lie outside of the polygon with a pink background and it draws parts of the … Continue reading

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

Enlarge a polygon in C#

This example shows how you can enlarge a polygon by a certain distance. For example, you can use it to move the edges of the polygon outward by 10 pixels. The program lets you use the mouse to define the … Continue reading

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

Platonic Solids Part 1: What are the Platonic solids?

This is the first in a series of posts about the Platonic solids. These posts will show how to find the corners of six Platonic solids: tetrahedron, cube (hexahedron), octahedron, dodecahedron, and icosahedron. Deriving these values requires only algebra and … Continue reading

Posted in algorithms, graphics, mathematics, wpf | Tagged , , , , , , , , , , , , , , , , , , , , , , , , , , | 2 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

Render polygons and polylines in a WPF program using C#

WPF lets you do all sorts of interesting things that are much harder in Windows Forms applications. However sometimes, as in this example, it makes simple things much harder. (WPF’s slogan should be, “Twice as flexible and only five times … Continue reading

Posted in drawing, extension methods, geometry, graphics, wpf, XAML | Tagged , , , , , , , , , , , , , , , , , , , , , , , | 2 Comments

Fill a polygon with a PathGradientBrush in C#

A PathGradientBrush defines a brush that shades smoothly from a “center point” to specific points along a path. This example fills a hexagon with colors that shade from white in the center to red, yellow, lime, cyan, blue, and magenta … Continue reading

Posted in graphics | Tagged , , , , , , , , , , , , , | 2 Comments

Draw striped lines in C#

You can use the Pen class to draw striped lines. That class’s CompoundArray property stores an array of floats that gives the fraction of the line’s width that is drawn and skipped. For example, the array 0.0, 0.25, 0.75, 1.0 … Continue reading

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

Draw a star with a given number of points in C#

My goal here was to draw a “normal” star where the interior concave angles were located at intersections of lines connecting the exterior convex points. This turned out to be a more interesting problem than I expected. There’s only one … Continue reading

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

Draw a non-intersecting star in C#

The following NonIntersectingStarPoints method generates the points needed to draw a non-intersecting star and returns them in an array. // Return PointFs to define a non-intersecting star. private PointF[] NonIntersectingStarPoints( int num_points, Rectangle bounds) { // Make room for the … Continue reading

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

Draw a star in C#

The following StarPoints method generates the points needed to draw a star and returns them in an array. // Return PointFs to define a star. private PointF[] StarPoints(int num_points, Rectangle bounds) { // Make room for the points. PointF[] pts … Continue reading

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