取得svg/xaml arc的分数 [英] Get points of svg/xaml arc
问题描述
svg arc的格式(xaml中的弧具有相同的args):
Format of svg arc (arc in xaml have same args):
(rx ry x-axis-rotation large-arc-flag sweep-flag x y)
说明:
从当前点到(x,y)绘制一个椭圆弧.椭圆的大小和方向由两个半径(rx,ry)和x轴旋转定义,x轴旋转指示椭圆整体如何相对于当前坐标系旋转.椭圆的中心(cx,cy)是自动计算的,以满足其他参数施加的约束.大弧标记和扫掠标记有助于自动计算,并有助于确定圆弧的绘制方式.
Draws an elliptical arc from the current point to (x, y). The size and orientation of the ellipse are defined by two radii (rx, ry) and an x-axis-rotation, which indicates how the ellipse as a whole is rotated relative to the current coordinate system. The center (cx, cy) of the ellipse is calculated automatically to satisfy the constraints imposed by the other parameters. large-arc-flag and sweep-flag contribute to the automatic calculations and help determine how the arc is drawn.
我需要计算它的所有圆弧(当然,需要一些步骤).我该怎么办?我想用C#或Java进行编码.
I need to calc all point of it arc (with some step, of course). How I can do it? I would like to code on C# or on Java.
推荐答案
Bresenham算法是为逐点绘制而发明的.
Bresenham algorithm is invented for point-by-point drawing.
Some code found for rotated ellipse (wayback machine)
已添加: 如何将以零为中心的椭圆转换为所需的隐式形式(A,B,C,D,E,F)
Added: How to transform zero-centered ellipse to needed implicit form (A,B,C,D,E,F)
A := (Cos(fi)/rx)^2 + (Sin(fi)/ry)^2;
C := (Sin(fi)/rx)^2 + (Cos(fi)/ry)^2;
B := Sin(2*fi)*(1/(ry*ry) - 1/(rx*rx));
D=E=0;
F:=-1
已检查rx = 100,ry = 60,fi = Pi/6:
Checked for rx=100, ry=60, fi=Pi/6:
另一步骤:Delphi函数获取任意椭圆的隐式形式. 我希望代码是可以理解的(Sqr(x)= x * x)
One more step: Delphi function to obtain implicit form for an arbitrary ellipse. I hope that code is understandable (Sqr(x) = x*x)
//calc implicit ellipse equation
//semiaxes rx, ry; rotated at fi radians; centered at (cx,cy)
//x = rx * Cos(t) * Cos(fi) - ry * Sin(t) * Sin(fi) + cx
//y = rx * Cos(t) * Sin(fi) + ry * Sin(t) * Cos(fi) + cy
//To obtain implicit equation, exclude t
//note: implicit form Ax^2+Bxy+Cy^2+Dx+Ey+F=0 (not 2B,2D,2E)
procedure CalcImplicitEllipseEquation(rx, ry, fi, cx, cy: Double;
var A, B, C, D, E, F: Double);
begin
B := Sin(2 * Fi) * (ry * ry - rx * rx);
A := Sqr(ry * Cos(fi)) + Sqr(rx * Sin(fi));
C := Sqr(rx * Cos(fi)) + Sqr(ry * Sin(fi));
D := -B * cy - 2 * A * cx;
E := -2 * C * cy - B * cx;
F := C * cy * cy + A * cx * cx + B * cx * cy - rx * rx * ry * ry;
end;
这篇关于取得svg/xaml arc的分数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!