问题描述
我在XAML中定义了ArcSegment,在后面的代码中,我需要进行计算以从圆弧的中心点到特定的Y点获取Y值。请查看图片以更好地了解。
XAML
<Canvas Name="canvas" Background="White" Opacity="99">
<Path Stroke="Red" MouseLeftButtonDown="Path_MouseLeftButtonDown">
<Path.Data>
<PathGeometry>
<PathFigureCollection>
<PathFigure StartPoint="250,250">
<ArcSegment Size="70,70" IsLargeArc="True" SweepDirection="Counterclockwise" Point="250,200"/>
</PathFigure>
</PathFigureCollection>
</PathGeometry>
</Path.Data>
</Path>
</Canvas>
C#
//I got this from StackOverflow maybe someone can figure out for the correct computation.
private void Path_MouseLeftButtonDown(object sender,MouseButtonEventArgs e)
{
var curve = sender as Path;
var geometry = curve.Data as PathGeometry;
var figure = geometry.Figures.FirstOrDefault();
var arcSegment = figure.Segments.FirstOrDefault() as ArcSegment;
var xStart = figure.StartPoint.X;
var yStart = figure.StartPoint.Y;
var startAngle = arcSegment.Point.X;
var sweepAngle = arcSegment.Point.Y;
var Rx = arcSegment.Size.Width; // this is radius width
var Ry = arcSegment.Size.Height; // this is radius height
var centerX = xStart - Rx * Math.Cos(startAngle);
var centerY = yStart - Ry * Math.Sin(startAngle);
var endAngle = startAngle + sweepAngle;
var xEnd = centerX + Rx * Math.Cos(endAngle);
var yEnd = centerY + Ry * Math.Sin(endAngle);
}
屏幕截图
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)