Geometry
The GeometryBase class and the classes which derive from it enable you to describe the geometry of a 2D shape. These geometric descriptions can be used for clipping and drawing.
This article covers the supported geometry types.
RectangleGeometry
RectangleGeometry represents a two-dimensional rectangle. The class exposes the following properties:
- Rect: The dimensions of the rectangle.
Example 1 shows how to create a RectangleGeometry.
Example 1: Create RectangleGeometry
RectangleGeometry rectangleGeometry = new RectangleGeometry();
rectangleGeometry.Rect = new Rect(10, 5, 400, 300);
PathGeometry
PathGeometry represents a complex shape that may be composed of curves and lines. The class exposes the following properties:
Figures: A collection of PathFigure objects which describe the contents of the PathGeometry.
-
FillRule: Specifies how the intersecting areas contained in the PathGeometry are combined.
EvenOdd: Determines whether a point is inside a path by drawing a ray from that point in any direction and simply counting the number of path segments that cross the ray. If the number is odd, the point is inside. If even, the point is outside.
Nonzero: Determines whether a given point is inside a path by conceptually drawing a ray from that point to infinity in any direction and then examining the places where a segment of the path crosses the ray. Starting with a count of zero, the rule adds one each time a path segment crosses the ray from left to right and subtracts one each time a segment crosses from right to left. After counting all the crossings, if the result is zero, the point is outside the path. Otherwise, it is inside.
Example 2 shows how to create a PathGeometry, which consists of line segments and bezier segments.
Example 2: Create PathGeometry
PathGeometry pathGeometry = new PathGeometry();
PathFigure pathFigure = pathGeometry.Figures.AddPathFigure();
pathFigure.StartPoint = new Point(5, 5);
LineSegment lineSegment = pathFigure.Segments.AddLineSegment();
lineSegment.Point = new Point(205, 5);
BezierSegment bezierSegment = pathFigure.Segments.AddBezierSegment();
bezierSegment.Point1 = new Point(105, 50);
bezierSegment.Point2 = new Point(130, 105);
bezierSegment.Point3 = new Point(100, 200);
pathFigure.IsClosed = true;
PathFigure
PathFigure represents a subsection of a PathGeometry.The class exposes the following properties:
Segments: A collection of PathSegment objects that define the shape of this PathFigure.
StartPoint: The point where the PathFigure begins.
IsClosed: Specifies whether the first and the last segments are connected.
PathSegment
PathSegment represents a segment of a PathFigure object. This abstract class is inherited from:
LineSegment
BezierSegment
QuadraticBezierSegment
LineSegment
Represents a segment, which creates a line between two points.The LineSegment class exposes the following properties:
- Point: The end point of the line segment.
BezierSegment
Represents a cubic Bezier curve drawn between two points.
Point1: The first control point of the curve.
Point2: The second control point of the curve.
Point3: The end point of the curve.
QuadraticBezierSegment
Represents a quadratic Bezier curve between two points. The QuadraticBezierSegment exposes the following properties:
Point1: The control point of the curve.
Point2: The end point of the QuadraticBezierSegment.
ArcSegment
Represents an elliptical arc between two points. The ArcSegment exposes the following properties:
Point: The endpoint of the elliptical arc.
RadiusX: The X radius of the arc.
RadiusY: The Y radius of the arc.
IsLargeArc: Specifies whether the arc should be greater than 180 degrees.
SweepDirection: Specifies whether the arc is drawn in the Clockwise or Counterclockwise direction.
RotationAngle: Specifies the amount (in degrees) by which the ellipse is rotated about the x-axis.