使用两个任意点之间的ArcSegment进行半圆的WPF数学运算 [英] WPF Math for semi circle using ArcSegment between two arbitrary points

查看:2236
本文介绍了使用两个任意点之间的ArcSegment进行半圆的WPF数学运算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以使用WPF中的ArcSegment显示在两个任意点之间绘制半圆的数学运算。

我对ArcSegment中的RadiusX RadiusY感到困惑。它似乎不是相对于两点而是相对于X轴和Y轴。 > ArcSegment 不是定义圆弧起点和终点的点之间的半径。该属性描述了在这些点之间绘制的椭圆应该有多大。如果你想要一个圆而不是一个椭圆,你必须记得总是将大小的x和y值设置为相同。如果你想总是画出一半的圆,你还需要确保 Size 将是这两点之间距离的一半。



例如,查看下面的代码:

 < Canvas> 
< Path Stroke =Black>
< Path.Data>
< PathGeometry>
< PathFigure StartPoint =100,100>
< ArcSegment IsLargeArc =True
Size =50,50
Point =200,100
SweepDirection =顺时针/>
< / PathFigure>
< / PathGeometry>
< /Path.Data>
< / Path>
< / Canvas>

这将绘制圆的上半部分,从 100点开始, 100 并结束于 200,100 点。因为我已经将 Size 属性设置为 50,50 (这些点之间的距离为100)一半的圈子。 SweepDirection 状态,该圆应该顺时针绘制,这就是它将绘制上半部分的原因。在下面的屏幕中查看顺时针逆时针之间的区别:




IsLargeArc 选择是否绘制更大的椭圆或更小的部分。由于我绘制了一半的圆,这没有意义,但是如果您绘制不同大小的椭圆,这将显着改变输出外观,只需使用它就可以了解其工作原理。



当您尝试将 200,200 大小的弧,顺时针它的大圆弧部分。正如你所看到的 - arc甚至不适合窗口(这是WPF设计者拍摄的,在正常的应用程序溢出部分将被截断)。


这是同样的事情,但设置为显示小弧:
< img src =https://i.stack.imgur.com/zYV9D.pngalt =200,200,顺时针,不是largearc>



当我将大小属性更改为 200,200 ,绘制的圆形只是4倍大,但仍然以精确的点开始和结束你定义了。 大小与点之间没有任何关系,您正在绘制椭圆/ cricle,但它会改变椭圆形外观。



我希望它能向你展示 Size 在 ArcSegment 中的含义,请随时询问更详细的内容问题,如果你仍然感到困惑。


Can someone show the math for drawing a semi circle between two arbitrary points using an ArcSegment in WPF.

I am quite confused with the RadiusX, RadiusY in the ArcSegment. It does not seem to be relative to the two points but rather to the X and Y axis. Is that how it really should be?

解决方案

You are right, Size of ArcSegment is not radius between points that define the start and end of the arc. This property describes how big the ellipse that will be drawn between those points, should be. If you want to have a circle instead of an ellipse, you must remember to always set size's x and y values to be the same. If you want to always have half of the circle drawn, you also need to make sure Size will be half of the distance between those two points.

For example look at the code below:

<Canvas>
    <Path Stroke="Black">
        <Path.Data>
            <PathGeometry>
                <PathFigure StartPoint="100,100">
                    <ArcSegment IsLargeArc="True"
                                Size="50, 50"
                                Point="200, 100"
                                SweepDirection="Clockwise" />
                </PathFigure>
            </PathGeometry>
        </Path.Data>
    </Path>
</Canvas>

This will draw upper half of the circle, that starts at point 100, 100 and ends at point 200, 100. Since I've set Size property to50, 50 (distance between those points is 100), this will create exactly half of circle. SweepDirectionstates, that circle should be drawn clockwise, and that's the reason why it will draw upper half. Check out the difference between Clockwise and Counterclockwise on screens below:

IsLargeArc chooses whether to draw bigger part of ellipse or smaller. Since I'm drawing half of circle, this has no meaning, but if you would draw ellipse with different size, this would significantly change output look, just play with it to see how it works.

This is how it looks when you try to put 200, 200 sized arc, clockwise using its large arc part. As you can see - arc does not even fit the window (this is shot from WPF designer, in normal app overflowing part would be cut off)

And this is the same thing but set to display small arc:

When I changed Size property to 200, 200, drawn circle is simply 4 times bigger, but still starts and ends at exact points you defined. Size has nothing to do with points, between which you're drawing your ellipse/cricle, but it changes the ellipse look.

I hope that it shows you what's the meaning of Size in ArcSegment, feel free to ask more detailed questions, if you're still confused.

这篇关于使用两个任意点之间的ArcSegment进行半圆的WPF数学运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆