SVG路径(path)中的圆弧(A)指令的语法说明及计算逻辑 您所在的位置:网站首页 指令的偏移量怎么计算 SVG路径(path)中的圆弧(A)指令的语法说明及计算逻辑

SVG路径(path)中的圆弧(A)指令的语法说明及计算逻辑

2024-04-13 12:44| 来源: 网络整理| 查看: 265

F.6.1 Elliptical arc syntax

An elliptical arc is a particular path command. As such, it is described by the following parameters in order:

(x1, y1) are the absolute coordinates of the current point on the path, obtained from the last two parameters of the previous path command.

rx and ry are the radii of the ellipse (also known as its semi-major and semi-minor axes).

φ is the angle from the x-axis of the current coordinate system to the x-axis of the ellipse.

fA is the large arc flag, and is 0 if an arc spanning less than or equal to 180 degrees is chosen, or 1 if an arc spanning greater than 180 degrees is chosen.

fS is the sweep flag, and is 0 if the line joining center to arc sweeps through decreasing angles, or 1 if it sweeps through increasing angles.

(x2, y2) are the absolute coordinates of the final point of the arc.

This parameterization of elliptical arcs will be referred to as endpoint parameterization. One of the advantages of endpoint parameterization is that it permits a consistent path syntax in which all path commands end in the coordinates of the new "current point". The following notes give rules and formulas to help implementers deal with endpoint parameterization.

F.6.2 Out-of-range parameters

Arbitrary numerical values are permitted for all elliptical arc parameters, but where these values are invalid or out-of-range, an implementation must make sense of them as follows:

If the endpoints (x1, y1) and (x2, y2) are identical, then this is equivalent to omitting the elliptical arc segment entirely.

If rx = 0 or ry = 0 then this arc is treated as a straight line segment (a "lineto") joining the endpoints.

If rx or ry have negative signs, these are dropped; the absolute value is used instead.

If rx, ry and φ are such that there is no solution (basically, the ellipse is not big enough to reach from (x1, y1) to (x2, y2)) then the ellipse is scaled up uniformly until there is exactly one solution (until the ellipse is just big enough).

φ is taken mod 360 degrees.

Any nonzero value for either of the flags fA or fS is taken to mean the value 1.

This forgiving yet consistent treatment of out-of-range values ensures that:

The inevitable approximations arising from computer arithmetic cannot cause a valid set of values written by one SVG implementation to be treated as invalid when read by another SVG implementation. This would otherwise be a problem for common boundary cases such as a semicircular arc. Continuous animations that cause parameters to pass through invalid values are not a problem. The motion remains continuous. F.6.3 Parameterization alternatives

An arbitrary point (x, y) on the elliptical arc can be described by the 2-dimensional matrix equation

equation F.6.3.1 (F.6.3.1)

(cx, cy) are the coordinates of the center of the ellipse.

rx and ry are the radii of the ellipse (also known as its semi-major and semi-minor axes).

θ is the angle from the x-axis of the current coordinate system to the x-axis of the ellipse.

θ ranges from:

θ1 which is the start angle of the elliptical arc prior to the stretch and rotate operations. θ2 which is the end angle of the elliptical arc prior to the stretch and rotate operations. Δθ which is the difference between these two angles.

If one thinks of an ellipse as a circle that has been stretched and then rotated, then θ1, θ2 and Δθ are the start angle, end angle and sweep angle, respectively of the arc prior to the stretch and rotate operations. This leads to an alternate parameterization which is common among graphics APIs, which will be referred to as center parameterization. In the next sections, formulas are given for mapping in both directions between center parameterization and endpoint parameterization.

F.6.4 Conversion from center to endpoint parameterization

Given the following variables:

cx cy rx ry φ θ1 Δθ

the task is to find:

x1 y1 x2 y2 fA fS

This can be achieved using the following formulas:

Equation F.6.4.1 (F.6.4.1) Equation F.6.4.2 (F.6.4.2) Equation F.6.4.3 (F.6.4.3) Equation F.6.4.4 (F.6.4.4) F.6.5 Conversion from endpoint to center parameterization

Given the following variables:

x1 y1 x2 y2 fA fS rx ry φ

the task is to find:

cx cy θ1 Δθ

The equations simplify after a translation which places the origin at the midpoint of the line joining (x1, y1) to (x2, y2), followed by a rotation to line up the coordinate axes with the axes of the ellipse. All transformed coordinates will be written with primes. They are computed as intermediate values on the way toward finding the required center parameterization variables. This procedure consists of the following steps:

Step 1: Compute (x1′, y1′)

Equation F.6.5.1 (F.6.5.1)

Step 2: Compute (cx′, cy′)

Equation F.6.5.2 (F.6.5.2)

where the + sign is chosen if fA ≠ fS, and the − sign is chosen if fA = fS.

Step 3: Compute (cx, cy) from (cx′, cy′)

Equation F.6.5.3 (F.6.5.3)

Step 4: Compute θ1 and Δθ

In general, the angle between two vectors (ux, uy) and (vx, vy) can be computed as

Equation F.6.5.4 (F.6.5.4)

where the ± sign appearing here is the sign of ux vy − uy vx.

This angle function can be used to express θ1 and Δθ as follows:

Equation F.6.5.5 (F.6.5.5) Equation F.6.5.6 (F.6.5.6)

where θ1 is fixed in the range −360° 



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有