WPF几何绘图(三)画弧线

WPF几何绘图(三)画弧线

ArcSegment 类来表示两点之间的一条椭圆弧。他表示的是椭圆上的一段弧线。

使用 PathFigure 对象存储 ArcSegment 对象和其他线段。

一条椭圆弧由下列元素定义:它的起点和终点、X 轴半径和 Y 轴半径、X 轴旋转因子、一个指示弧是否应大于 180 度的值和一个描述弧的绘制方向的值。ArcSegment 类不包含弧的起点属性,它仅定义它所要表示的弧的目标点。弧的起点是 PathFigure(其中添加了 ArcSegment)的当前点。

实例代码如下:

Point arcEndPt = new Point(200, 100); Size arcSize = new Size(75, 75); double rotationAngle = 360; SweepDirection direction = SweepDirection.Clockwise; ArcSegment arcsegment = new ArcSegment(arcEndPt, arcSize, rotationAngle, false, direction, true); PathSegmentCollection pathsegmentCollection = new PathSegmentCollection(); pathsegmentCollection.Add(arcsegment); PathFigure pathFigure = new PathFigure(); pathFigure.StartPoint = new Point(50, 100); pathFigure.Segments = pathsegmentCollection; PathFigureCollection pathFigureCollection = new PathFigureCollection(); pathFigureCollection.Add(pathFigure); PathGeometry pathGeometry = new PathGeometry(); pathGeometry.Figures = pathFigureCollection; Path myPath = new Path(); myPath.Stroke = Brushes.Black; myPath.StrokeThickness = 1; myPath.Data = pathGeometry;

 

对于ArcSegment构造函数参数的一些解释:

(1)IsLargeArc 和 SweepDirection


对于大多数具有特定位置、大小和旋转角度的弧,可以绘制四种不同的弧;IsLargeArcSweepDirection 属性指示要使用哪种弧。

在这四种候选弧扫掠中,两种表示扫掠 180 度或大于 180 度的大弧,另外两种表示扫掠 180 度或小于 180 度的小弧。如果 IsLargeArctrue,则选择一种大弧扫掠;如果为 false,则选择一种小弧扫掠。其余两种候选弧分别以不同方向绘制:Counterclockwise ClockwiseSweepDirection 属性指定要使用哪个方向。

 


(2)Point


得到和设置圆弧的一个顶点.
 
可以读/写.默认为"0,0"

一个ArcSegment的定义就是指定圆弧的顶点,并呈现出来,这个顶点开始于point of PathFigure结束于 ArcSegment的Point.


(3)RotationAngle



 get或set关于X轴旋转的椭圆.(单位degrees).

返回Double类型
关于X轴旋转的椭圆

可以读/写,默认值为"0";


(4)Size


Get/Set 弧所在椭圆的的X-和Y-半径。

 


(5)SweepDirection



Gets或sets 弧是按顺时针方向还是逆时针方向绘制.

返回值是SweepDirection类型.

用一个值来描述弧的绘制方向.
这个属性是read/write.默认值Counterclockwise.

一个ArcSegment关于给定的Size, RotationAngle, start point,和end Point,会有四个不同的弧.指定IsLargeArc属性可能简化两种弧:一个是从start point到end Point按顺时针方向绘制的和一个是从start point到end Point按逆时针方向绘制的.

 

在 XAML 中,还可以通过显式使用对象标记来绘制椭圆弧。

你可能感兴趣的:(WPF几何绘图(三)画弧线)