wpf 如何使用椭圆类绘制圆形扇区?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6744350/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I draw a circle sector with the ellipse class?
提问by laszlokiss88
I would like to make a sector of a circle on WP7. I tried to do this with the ellipse class and I found a lot of solution, which make a gauge or pie chart or something, but I need just the essence. Could anyone help?
我想在 WP7 上做一个圆的扇区。我试图用椭圆类来做到这一点,我找到了很多解决方案,可以制作仪表或饼图之类的东西,但我只需要本质。有人可以帮忙吗?
the aim is to show just one part of a circle (or ellipse). Like the yellow area in the picture:
目的是只显示圆(或椭圆)的一部分。像图中黄色区域:
Thanks, Laci
谢谢,拉西
回答by devuxer
Here's a fairly simple solution to the problem, though it does not use an Ellipse
and it requires a little trigonometry:
这是该问题的一个相当简单的解决方案,尽管它不使用 anEllipse
并且需要一点三角学:
<Path Fill="Black"
Data="M0,0 L0,-100 A100,100 0 0 1 70.7,-70.7 z" />
The Data
property uses Path Markup Syntax.
该Data
属性使用Path Markup Syntax。
- The "M" at the beginning tells the pen to Move to the location 0,0.
- The "L" tells the pen to draw a Line from the current location (0, 0) to 0,-100.
- The "A" tells the pen to draw an elliptical Arc from the current location to 70.7,-70.7 (the "100,100" portion determines the horizontal and vertical radius of the ellipse and the "0 0 1" portion is for
RotationAngle
,IsLargeArc
, andSweepDirection
(1 for clockwise, 0 for counter-clockwise)). - The "z" tells the pen to close or complete the shape (which will cause a line to be drawn from 70.7,-70.7 back to 0,0).
- 在“M”开头讲述了笔中号奥雅纳的位置0,0。
- 的“L”告诉笔绘制一个大号从当前位置(0,0)INE为0,-100。
- 的“A”告诉笔绘制椭圆甲从当前位置到RC 70.7,-70.7(以下简称“100100”部分确定椭圆的水平和垂直半径和“0 0 1”部分是用于
RotationAngle
,IsLargeArc
和SweepDirection
(1 为顺时针,0 为逆时针))。 - “z”告诉笔关闭或完成形状(这将导致从 70.7,-70.7 绘制一条线回到 0,0)。
Where did the 70.7 come from? Well, this particular arc sweeps out an angle of 45 degrees from a circle with radius 100, so the coordinates 70.7,-70.7 are determined by 100 * sin(45)
and 100 * cos(45)
.
70.7从哪里来?嗯,这个特殊的弧从半径为 100 的圆扫出 45 度角,因此坐标 70.7,-70.7 由100 * sin(45)
和确定100 * cos(45)
。
回答by Mo Valipour
You need to do something like this:
你需要做这样的事情:
- define a canvas wrapper for ellipse
define the visible part of the canvas (clip). For this part you need to use PathGeometryas the Clip to define the slice of the circle you want to be visible. (see link)
<Canvas> <Canvas.Clip> <PathGeometry> // define your path here (see link above) </PathGeometry> <Ellipse Background="Yellow" Width="200" Height="200" /> </Canvas.Clip> </Canvas>
- 为椭圆定义画布包装器
定义画布(剪辑)的可见部分。对于这部分,您需要使用PathGeometry作为 Clip 来定义您想要可见的圆的切片。(见链接)
<Canvas> <Canvas.Clip> <PathGeometry> // define your path here (see link above) </PathGeometry> <Ellipse Background="Yellow" Width="200" Height="200" /> </Canvas.Clip> </Canvas>
Alternatively you can use CombinedGeometryto combine a PathGeometry
and EllipseGeometry
to form the slice. (the link provides a good example of CombinedGeometry
)
或者,您可以使用CombinedGeometry组合 aPathGeometry
和EllipseGeometry
以形成切片。(该链接提供了一个很好的例子CombinedGeometry
)