我正在进行涉及弧线的倒计时项目。我现在一直在努力学习数学,希望有人能帮助我。我有一个150px的圆圈,我想绘制从顶部开始运行的弧线。圆(椭圆真的)是160,4在Silverlight中绘制弧线
<Ellipse Height="150" HorizontalAlignment="Left" Margin="160,4,0,0"
Name="minutesClock" Stroke="Gainsboro" StrokeThickness="20"
VerticalAlignment="Top" Width="150" />
我对任何的秒数留
private void drawArc(int timevalue, int maxvalue)
{
Ellipse element = (Ellipse)LayoutRoot.FindName("minutesClock");
double top = element.Margin.Top;
double left = element.Margin.Left;
double width = element.Width;
double height = element.Height;
double strokeWidth = element.StrokeThickness;
double startX = left + (width/2);
double startY = top + (strokeWidth/2);
double radius = (width/2) - (strokeWidth/2);
double percent = (double)timevalue/(double)maxvalue;
Point center = new Point();
center.X = top + (height/2);
center.Y = left + (width/2);
Point newEnd = calculatePoint(radius, percent, center);
Path arc = (Path)LayoutRoot.FindName(what + "Arc");
PathFigure path = new PathFigure();
path.StartPoint = new Point(startX, startY);
ArcSegment arcSegment = new ArcSegment();
arcSegment.IsLargeArc = false;
Size arcSize = new Size(radius,radius);
arcSegment.Size = arcSize;
arcSegment.SweepDirection = SweepDirection.Clockwise;
arcSegment.Point = newEnd;
arcSegment.RotationAngle = 45;
path.Segments.Add(arcSegment);
PathGeometry pg = new PathGeometry();
pg.Figures = new PathFigureCollection();
pg.Figures.Add(path);
arc.Data = pg;
}
是应该从圆心顶部计算弧段的方法弧线从正确的位置开始,但不会在正确的位置结束(终点遍布整个地方)。我的calculatePoint代码必须是错误的地方。我认为它有点关系
private Point calculatePoint(double radius, double percent, Point center)
{
double degrees = 90 - (360 * percent);
double radians = (Math.PI * degrees)/180;
Point endPoint = new Point();
endPoint.X = center.X + (radius * Math.Sin(radians));
endPoint.Y = center.Y + (radius * Math.Cos(radians));
return endPoint;
}
我在哪里出错了?
对不起,我很难理解你想如何绘制圆弧:“[...]从圆的中心顶部到任何剩余秒数”。那么我想象一个时钟,你想在边缘画一个弧,起点在12点。你的意思是一个完整的圆圈是60秒(这意味着“剩余秒数”的最大数量是60)?弧线必须顺时针绘制? – Martin