简体   繁体   English

如何画一个(值)%的圆

[英]How to draw a (value)% Circle

I want to use Path to draw a partly circle like 25% circle (1/4, 90degree circle, 360 degree is a full circle) I can use ArcSegment to do that, but 25% is easy because the number is simple and you can easily guess the point. 我想使用Path绘制一个像25%的圆(1 / 4、90度的圆,360度是一个完整的圆)的局部圆,我可以使用ArcSegment来做到这一点,但是25%很容易,因为数字很简单,您可以轻松猜测要点。 But when I want to draw a 20% circle 1/5 72degree circle) I can't guess anymore be cause the is not a float value so I came up with 4 Equations 但是,当我想绘制20%的圆(1/5 72度的圆)时,我无法再猜测了,因为它不是浮点值,所以我想出了4个方程式

For 0->90 degree (unit value = Degree (Eg: 20degree)) x,y = ArcSegment.Point(x,y)
 x = (PathWidth / 2) + [Sin(value) *50] 
 y = [Sin(value) *50]
For 90->180 degree 
 x, y= (PathWidth / 2) + [Sin(value) *50]
For 180->270 : Sorry I don't know ;(

For example I want a 25% circle in a 100x100 Path (Start point is 50,0) then 25% is 1/4 = 90 degree: Apply my equation I mention above, We have: 例如,我想在100x100路径中(起点为50,0)设置25%的圆,然后25%为1/4 = 90度:应用我上面提到的公式,我们有:

x = (100/2) + Sin(90) * 50 = 100
y = Sin(90) * 50 = 50

So the ArcSegment.Point="100,50" and we a 50% circle 因此,ArcSegment.Point =“ 100,50”,我们绕了50%

But I think the equation is not effective and maybe( I not verify yet) Inaccurate and we need 4 equations to accomplish the a partly circle (1->99%) circle. 但我认为该方程式无效,并且可能(我尚未验证)不准确,我们需要4个方程式才能完成部分圆(1-> 99%)的圆。 So Could you improve the equation I use above 所以你能改善我上面使用的方程式吗

Sorry for my bad English because English is not my first language. 对不起,我的英语不好,因为英语不是我的母语。

The following method creates a PathGeometry with a single circular ArcSegment , which will work from 0 up to, but not including, 360 degrees. 以下方法使用单个圆形ArcSegment创建一个PathGeometry ,它将在0到但不包括360度的范围内工作。 The center of the circle is a coordinates (0, 0) . 圆的中心是坐标(0, 0)

It is important to set the ArcSegment's IsLargeArc property to true if the angle is larger than 180 degrees. 如果角度大于180度,则将ArcSegment的IsLargeArc属性设置为true很重要。

private Geometry CreateArc(double radius, double angle)
{
    var endPoint = new Point(
        radius * Math.Sin(angle * Math.PI / 180),
        radius * -Math.Cos(angle * Math.PI / 180));

    var segment = new ArcSegment(
        endPoint, new Size(radius, radius), 0,
        angle >= 180, SweepDirection.Clockwise, true);

    var figure = new PathFigure { StartPoint = new Point(0, -radius) };
    figure.Segments.Add(segment);

    var geometry = new PathGeometry();
    geometry.Figures.Add(figure);

    return geometry;
}

If you need to draw a full circle, you'll have to add a second ArcSegment, or return an EllipseGeometry. 如果需要绘制一个完整的圆,则必须添加第二个ArcSegment,或者返回EllipseGeometry。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM