Menu

wxdkdraw technical details

Dirk Krause
← Previous ↑ Home → Next

German version available: Technische Details zu wxdkdraw und wxd2lat

Technical details on wxdkdraw and wxd2lat

Requirements

The following requirements were formulated when designing the file format and the wxdkdraw and wxd2lat programs:

  • Use with LaTeX or pdfLaTeX
    The file formats used for export are PDF+TEX, EPS+TEX and PGF.
    For PDF+TEX and PGF output, either
    • a *.tex file can be created that is integrated into another *.tex file or
    • a *.tex file that can be processed directly by pdfLaTeX.

     
  • Graphic elements
    The choice of available graphic elements should correspond approximately to the graphic elements available in XFig.
     
  • Electronic circuits
    In electronic circuits, electrical connections between two intersecting lines are marked by a filled circle. A special graphic element (the filled dot) is provided for this purpose, a filled circle with a small radius, which is placed by center point. In contrast to the circle as a normal graphic element, this circle is filled with the drawing color, not the fill color. A white-filled circle with a small radius is used for ports (inputs/outputs) of circuits. The circles for connection points and ports are automatically placed in the layer above the current layer.
     
  • Optical and magnetic grid
    Drawing takes place exclusively on a rectangular grid. The optical grid is displayed on the screen and is used for orientation. The graphic elements are aligned on the magnetic grid, which is finer than the optical grid.
     
  • Inches and centimeters
    Drawing should be possible both in an inch-based grid and in a centimeter-based grid.
     
  • Grid base 2 or 5
    It should be possible to choose whether half an inch or one centimeter is divided into 4 or 5 magnetic grid spacing intervals.
     
  • Dynamic grid
    When zooming in, the grid should adjust dynamically. This means that zooming in not only enables more precise viewing but also finer drawing.
     
  • Responsiveness of the drawing program
    The wxdkdraw program should interact with the user at normal speed.
     
  • High-quality output for export
    The wxd2lat program is designed to generate high-quality graphics during export. More complex calculations are also accepted for this purpose.

Conclusions

  • Integer coordinate values
    Integer values are used to store coordinates. However, as conversion to floating point numbers is required for export and some calculations, only 32-bit values can be used, as these can be converted to the “double” data type without loss. The “double” data type uses 51 bits in the mantissa field, this allows to represent 52 bit integer values. So we can not use 64 bit integer values for coordinates.
     
  • Requirements for the WXD resolution
    The WXD resolution (number of wxd units per inch) is a compromise between two different requirements:
     
    • A high resolution allows fine drawing.
       
    • However, as only a numerical range of −231 … 231−1 is available for coordinates, a low resolution allows a larger extension of the drawing.
       
  • Caching in the drawing program
    3 different cache bitmaps are used in wxdkdraw:
     
    • Grid
      The “deepest” drawing operations draw the border area in light blue, the drawing background in light gray and the optical grid in the form of horizontal and vertical lines. The result of these drawing operations is stored in a bitmap. The bitmap is only regenerated when required, e.g. when scrolling, zooming, or resizing the window.
       
    • Drawing
      The “middle” drawing operations first transfer the grid cache and draw the graphic elements on it, possibly with the exception of elements currently being edited. The result of these operations is in turn stored in a bitmap.
       
    • Markup
      The “top” drawing operations first transfer the drawing cache and draw the markup on top of it, e.g. the wxdkdraw cursor, the placement aid and graphic elements to be copied/moved or markers for candidates of copy/move/delete operations. The result of these operations is stored in a bitmap.
       
  • Curved arrowheads, length correction for arrowheads
    High-quality output should be generated in the export file. The arrowheads should end exactly at the specified end point of a line. On curved lines (arcs and X-splines), the arrowheads should follow the curvature. For splines this requires complex calculations using iterative algorithms. This is acceptable for the wxd2lat export program, but not for the wxdkdraw interactive drawing program, as these calculations would result in stagnation when scrolling or moving graphic objects. Therefore, only an approximation of the arrowhead is displayed in wxdkdraw.

Selected mathematical problems

Calculating the WXD resolution

Users should have the choice between a grid based on inches and a grid based on centimeters. An integer number of wxd units should be used for both grids.
Equation (1) shows the conversion of the number of wxd units per inch into the number of wxd units per centimeter.
The WXD resolution (number of wxd units per inch) must contain the factor 127 so that the number of wxd units per centimeter is also an integer.

(1) r wxd,cm = 50 127 r wxd,inch (2) f inch,cm = 127

At zoom level 0 (factor 1=100%), one inch is divided into either 8 or 10 intervals to form the magnetic grid. One centimeter is divided into either 4 or 5 intervals.
To ensure that the points of the magnetic grid are also at integer values, the WXD resolution must contain a factor

(3) f grid = lcm ( 4 , 5 , 8 , 10 ) = 40

The operator lcm(…) is used here to denote the least common multiple.

When zooming up to zoom level 14, zoom factors of up to 128 are possible. Decimal zooming up to a factor of 100 should also be possible.
So the WXD resolution must contain an additional factor

(4) f zoom = lcm ( 128 , 100 ) = 3200

to ensure that the magnetic grid points lie on integer coordinates even if the magnetic grid interval is reduced by a factor of 1128 or 1100.

All three factors are used to calculate the WXD resolution:

(5) r wxd,inch = f inch,cm f grid f zoom = 127 40 3200 = 16256000

The WXD file format uses a resolution of 16256000 wxd units per inch.

Arrowhead corrections

Arrowhead

The illustration shows a line coming from the left and ending at point P0. An arrowhead is added to this line, which is drawn as a polyline P1P0P2 using the same line width l as used for the actual line. As you can see, the arrowhead ends at point PE with distance s to P0.

The end point specified in the WXD file is point PE. The actual line must therefore be shortened slightly so that it ends in the area between PA and PB. To end in PA the line must be shortened by cmax, to end in PB the line must be shortened by cmin.
If the opening angle of the arrowhead is denoted by α, we can calculate:

(6) l 2 = s sin ( α2 ) = s w a 2 l a 2 + 1 4 w a 2 (7) s = l w a l a 2 + 14 l a 2 (8) l 2 c min = tan ( α 2 ) = w a 2 l a (9) cmin = l l a w a < s (10) cmax = 2 s (11) c = 12 ( c max + c min ) (12) Δ c = 12 ( c max - c min )

For polylines and circular arcs, the shortening is by cmin in each case; the end point or required end angle can be calculated exactly.
For splines, an iterative method is used to find a solution in order to achieve a reduction by c according to equation 11 with a tolerance Δc according to equation (12).

Polylines

Length correction for arrowheads

The following formulas are used for length correction on the final segment with penultimate point P0(x0;y0) and final point P1(x1;y1) if the second step results in a positive q value:

(13) l s = ( x 1 - x 0 ) 2 + ( y 1 - y 0 ) 2 (14) q = l s - c min l s (15) x 1 ' = x 0 + q ( x 1 - x 0 ) (16) y 1 ' = y 0 + q ( y 1 - y 0 )

The final segment is drawn from point P0(x0;y0) to point P1'(x1';y1').

Arcs

Calculating center point and radius

The following equations apply to an arc with center Pc(xc;yc) and radius r given by three consecutive points

  • Start point P1(x1;y1),
  • Point on arc P2(x2;y2) und
  • Final point P3(x3;y3):
(17) r2 = ( x 1 - x c ) 2 + ( y 1 - y c ) 2 (18) r2 = ( x 2 - x c ) 2 + ( y 2 - y c ) 2 (19) r2 = ( x 3 - x c ) 2 + ( y 3 - y c ) 2

This system of equations (17,18,19) can be solved for xc, yc and r.
The solutions for xc and yc are shown below in equations (20) and (21). The solution for r is relatively complicated. It is easier to determine r by substituting xc and yc into one of the equations above.

(20) x c = - ( y2 - y1 ) y32 + ( - y22 + y12 - x22 + x12 ) y3 + y1 y22 + ( - y12 + x32 - x12 ) y2 + ( x22 - x32 ) y1 2 ( ( x2 - x1 ) y3 + ( x1 - x3 ) y2 + ( x3 - x2 ) y1 ) (21) yc = ( x2 - x1 ) y32 + ( x1 - x3 ) y22 + ( x3 - x2 ) y12 + ( x2 - x1 ) x32 + ( x12 - x22 ) x3 + x1 x22 - x12 x2 2 ( ( x2 - x1 ) y3 + ( x1 - x3 ) y2 + ( x3 - x2 ) y1 )

We have to take care of the following special cases:

  • Identical points
    2 or all 3 points are identical.
     
  • Line
    The points are on a line.

The vector product P1P2×P2P3 is considered to check for the special cases. Since P1, P2 and P3 only have x- and y components, the vector product only has a z component:

(22) z = ( x2 - x1 ) y3 + ( x1 - x3 ) y2 + ( x3 - x2 ) y1

If the z component is positive, the arc rotates in the mathematically positive direction (counterclockwise).
If the z component is negative, the arc rotates in the mathematically negative direction.
If the z component is 0, one of the above-mentioned special cases occurs. In this case, it is not a circular arc. xc, yc and r cannot be calculated.

Length correction for arrowheads

If a circular arc from P0 to P1is given by the radius r and the angle α and is to be shortened so that the distance between the new end point P1' and the old end point P1 is c, the angle shortening αc can be calculated as follows:

(23) c = ( x 1 ' - x 1 ) 2 + ( y 1 ' - y 1 ) 2 = ( r cos αc - r ) 2 + ( 0 - r sin αc ) 2 = r2 - 2 r2 cos αc + r2 cos2 αc + r2 sin2 αc = r 1 - 2 cos αc + cos2 αc + sin2 αc = r 2 - 2 cos αc (24) 2 - 2 cos αc = ( c r ) 2 (25) 2 cos αc = 2 - ( c r ) 2 (26) cos αc = 1 - c 2 2 r 2 (27) αc = arccos ( 1 - c2 2 r2 )

Rotated ellipses

Overview

To apply a fill pattern to a rotated ellipse, the bounding box of the rotated ellipse must be determined (minimum and maximum of the x and y extent of the ellipse).
The clip region is set to the path of the ellipse, then the fill pattern is drawn in the bounding box.

Distance of a point to a straight line through the zero point

For calculations on rotated ellipses, a formula for the distance d of a point P(xp;yp) to a straight line through the coordinate origin with the angle β is required.

Equation (28) applies to the straight line:

(28) k ˜ G : r ( t ) = t ( cos β sin β )

For the distance between P and a straight line point given by t, equation (29) applies:

(29) l ( t ) = ( t cos β - xp ) 2 + ( t sin β - yp ) 2

The distance from the point to the straight line is equal to the length of the perpendicular from the point to the straight line. The scalar product of the perpendicular vector and the straight line vector must be 0.

(30) 0 = ( r ( tL ) - r p ) · r ( tL ) = ( t L cos β - xp t L sin β - yp ) · ( t L cos β t L sin β ) = tL2 cos2 β - xp tL cos β + tL2 sin2 β - yp tL sin β = tL ( tL - ( xp cos β + yp sin β ) ) (31) tL = xp cos β + yp sin β (32) d = l ( tL ) = ( yp - ( yp sin β + xp cos β ) sin β ) 2 + ( xp - ( yp sin β + xp cos β ) cos β ) 2

For the apparent solution tL=0 the scalar product also results in 0, but not because of a right angle between the vectors, but because one vector has the length 0.

Bounding box of the rotated ellipse

Rotated ellipse
To determine the bounding box of an ellipse rotated by α, the height h of the highest point and the width w of the point furthest to the right are required.
In the left-hand diagram, g1 is the upper horizontal tangent, g2 is the right-hand vertical tangent. The height h is the distance between the point of contact Ph and the x-axis. The width w is the distance between the point of contact Pw and the y-axis.
For the calculation, the entire arrangement is rotated back by α, the ellipse is aligned with the axes again. The straight lines g1 and g2 are no longer parallel to the axes. The auxiliary lines h1 and h2 are obtained from the rotation of the axes. The height h is now the distance from the point Ph to the auxiliary line h1 (formerly x-axis). The width w is now the distance from the point Pw to the auxiliary line h2 (formerly y-axis).

(33) k ˜ E : r ( t ) = ( rx cos t ry sin t ) 0 t 2 π (34) ddt r = ( - rx sin t ry cos t ) (35) tan ( π - α ) = ry cos th - rx sin th (36) th = arctan ( - ry rx tan ( π - α ) ) (37) tan ( π2 - α ) = ry cos tw - rx sin tw (38) tw = arctan ( - ry rx tan ( π2 - α ) )

Equation (33) describes the curve of a non-rotated ellipse aligned along the axes as shown in the figure on the right. The ellipse is drawn in a mathematically positive sense.
The direction vector at each point is the first derivative according to equation (34).

For point Ph, this direction vector must have the angle π-α according to equation (35).
This can be converted to equation (36) to determine th.

Similarly, the direction vector for point Pw must have the angle π2-α.
This means that tw can be determined using equation (38).

Using th and tw, we can calculate Ph(xh;yh) and Pw(xw;yw).

The height h of the rotated ellipse is now the distance from the point Ph(xh;yh) to the straight line h1 through the coordinate origin with the angle βh=-α.

The width w of the rotated ellipse is now the distance from the point Pw(xw;yw) to the straight line h2 through the coordinate origin with the angle βw=π2-α.

The following applies to the bounding box of a rotated ellipse with center in the coordinate origin:

(39) xl = - w  Left boundary (40) xr = w  Right boundary (41) yb = - h  Lower boundary (42) yt = h  Upper boundary

If the center of the rotated ellipse is not at the coordinates origin, the bounding box also shifts accordingly.

Splines

Overview

Curves in 2 can be described by equation:

(43) k ˜ : r ( t ) = ( x ( t ) y ( t ) ) ts t te

In the field of computer graphics, 0t1 is often used for the entire curve or for a curve segment.

A spline describes a continuous curve by a set of discrete values.

Bezier splines

For cubic Bezier splines, each segment is described by start point Ps(xs;ys) and end point Pe(xe;ye) as well as two control points Pcs(xcs;ycs) and Pce(xce;yce).
Pcs denotes the control point “to the right” of the start point. Pce denotes the control point “to the left” of the end point.
In the literature, the notation Pi and Pj is often used for the start and end points and Pi+ and Pj- or Pi+ and Pj- for the control points.

(44) r ( t ) = ( 1 - t ) 3 · r s + 3 · ( 1 - t ) 2 · t · r cs + 3 · ( 1 - t ) · t2 · r ce + t3 · r e (45) r ˙ = d dt r = ( - 3 + 6 t - 3 t2 ) r s + 3 ( 1 - 4 t + 3 t2 ) r cs + 3 ( 2 t - 3 t2 ) r ce + 3 t2 r e (46) r ˙ ( 0 ) = - 3 r s + 3 r cs (47) r ˙ ( 1 ) = - 3 r ce + 3 r e (48) r cs = r s + 13 r ˙ ( 0 ) (49) r ce = r e - 13 r ˙ ( 1 )

The segment is traversed with the parameter t in the interval 0t1, resulting in curve point vectors according to equation (44).

The first derivative according to equation (45) gives the direction vectors.

This results in direction vectors at the boundary points corresponding to equations (46) and (47).

These equations can be rearranged to equations (48) and (49) in order to calculate the control points if the first derivative of the position vector in the boundary points is known.

One disadvantage of Bezier splines is that it is difficult for inexperienced users to estimate how manipulating the control points will affect the curve.

Bounding box of Bezier spline segments

To determine the bounding box of a Bezier spline segment, extreme points of the x and y values for 0t1 must be taken into account in addition to the start and end points.

(50) x ( t ) = ( 1 - t ) 3 xs + 3 ( 1 - t ) 2 t xcs + 3 ( 1 - t ) t2 xce + t3 xe (51) = a t3 + b t2 + c t + d (52) a = xe - 3 xce + 3 xcs - xs (53) b = 3 xce - 6 xcs + 3 xs (54) c = 3 xcs - 3 xs (55) d = xs (56) 0 = d x d t | t = tm (57) tm = { - b ± b 2 - 3 a c 3 a  if  a 0 - c 2 b  if  a = 0  and  b 0   no solution  if  a = 0  and  b = 0

Equation (50) shows the calculation of the x coordinate as a function of t.
This calculation can be simplified to a polynomial of t, the coefficients ad are determined using equations (52) to (55).

For local extrema, the first derivative is 0, see equation (56).

If equation (51) is a cubic polynomial with a0, there are 2 extreme points corresponding to equation (57).
If equation (51) is a quadratic polynomial with a=0 and b0, there is only one extreme point.
If both a=0 and b=0, the line is straight and there are no local extrema.

For the local extreme points tm with 0tm1, the x values must be calculated and taken into account when determining the bounding box.

The same procedure must be followed for the y values.

Approximation of circular arcs using Bezier splines

The following investigation was inspired by the German Wikipedia page on “Bezierkurven” (Bezier curves). There a method is given how control points can be obtained for the approximate representation of a quarter circle by a Bezier spline segment. This method is generalized here in order to be able to represent circular arcs with any opening angle. In wxd2lat the formula is used for circular arc segments with |α|π2, larger circular arcs are then realized by several Bezier segments. The previous section showed how the control points for a Bezier spline segment can be obtained from the start and end points of a parametric curve and the coordinate derivatives in the start and end points. This generates a Bezier spline segment that comes as close as possible to the x(t) and y(t) curves. However, the main aim of the approximation is to achieve the best possible approximation to the desired x-y-curves. It is therefore investigated here whether a variation of the control points leads to better results.

The Bezier curves, whose control points were obtained using equations (48) and (49), have the required radius at start and end point, but in the interior of the interval the curve runs inside the circle, i.e. the radius is undershot. To change the curve, the control points are moved a little further away from the start and end points, but they remain on the tangents at the start and end points. Due to the symmetry of the arrangement, both control points are kept at the same distance from the respective end point.

(58) k ˜ k : r k ( t ) = ( r cos ( α t ) r sin ( α t ) ) (59) r · k = d dt r k = ( - r α sin ( α t ) r α cos ( α t ) ) (60) r s = r k ( 0 ) = ( r 0 ) (61) r e = r k ( 1 ) = ( r cos α r sin α ) (62) r cs = r s + κ r · k ( 0 ) (63) r ce = r e - κ r · k ( 1 ) (64) k˜ b : r b ( t ) = ( 1 - t ) 3 r s + 3 ( 1 - t ) 2 t ( r s + κ r · k ( 0 ) ) + 3 ( 1 - t ) t2 ( r e - κ r · k ( 1 ) ) + t3 r e (65) r = | r b ( 12 ) | (66) κ = 2 8 ( 1 - cos α ) - 4 sin α 3 α ( 1 - cos α )

Equation (58) applies to the vectors of the points on the arc.
The direction vector at each point is calculated from the first derivative according to equation (59).
The start and end points of the arc are given by equations (60) and (61).
In the calculation of the control points with equations (62) and (63), the derivatives are not multiplied by a factor of 13, but by a still unknown coefficient κ.
This coefficient κ must be selected so that the center of the Bezier segment has the distance r to the center of the circular arc. This requirement is formulated as equation (65).
If equation (64) is inserted into equation (65) and converted to κ, the solution corresponding to equation (66) is obtained.

This results in quite long equations. The mathematics software wxMaxima with the following commands was therefore used to insert, convert and solve equations:

/* x and y coordinates of the circular arc. */
X: R * cos(alpha * t);
Y: R * sin(alpha * t);

/* First and final point of the arc. */
xs: at(X, t=0);
ys: at(Y, t=0);
xe: at(X, t=1);
ye: at(Y, t=1);

/* First derivative of the coordinates. */
dXdt: diff(X, t);
dYdt: diff(Y, t);

/* Control point formulas, kappa is still unknown. */
xcs: xs + kappa * at(dXdt, t=0);
ycs: ys + kappa * at(dYdt, t=0);
xce: xe - kappa * at(dXdt, t=1);
yce: ye - kappa * at(dYdt, t=1);

/* x and y coordinates of the Bezier spline. */
xb: (1-t)^3*xs + 3*(1-t)^2*t*xcs + 3*(1-t)*t^2*xce + t^3*xe;
yb: (1-t)^3*ys + 3*(1-t)^2*t*ycs + 3*(1-t)*t^2*yce + t^3*ye;

/* For t=0.5 the distance from the center point to the
   Bezier spline point is required to be R.
   We are searching for an appropriate kappa.
*/
res: solve( at(xb,t=1/2)^2 + at(yb,t=1/2)^2 = R^2, kappa);

/* Simplify result. */
trigsimp(rhs(res[2]));

X-splines

Cross-splines (X-splines) were introduced in 1995 by Carole Blanc and Christophe Schlick. X-splines are not explained in detail here, please refer to the corresponding SIGGRAPH publication 〈BS1995〉. The description here is limited to the use of X-splines in WXD files and the handling in the programs wxdkdraw and wxd2lat.

(67) f ( u , p ) = { u3 ( 10 - p + ( 2 p - 15 ) u + ( 6 - p ) u2 )  if  u [ 0 ; 1 ] 0  otherwise (68) e ( u , p , q ) = { q u + 2 q u2 - 2 q u4 - q u5  if  u [ -1 ; 0 ) q u + 2 q u2 + ( 10 - 12 q - p ) u3 + ( 2 p + 14 q - 15 ) u4 + ( 6 - 5 q - p ) u5  if  u [ 0 ; 1 ] 0  otherwise (69) r ( u , p ) = df du = { 5 ( 6 - p ) u4 + 4 ( 2 p - 15 ) u3 + 3 ( 10 - p ) u2  if  u [ 0 ; 1 ] 0  otherwise (70) s ( u , p , q ) = de du = { q + 4 q u - 8 q u3 - 5 q u4  if  u [ -1 ; 0 ) 5 ( 6 - 5 q - p ) u4 + 4 ( 2 p + 14 q - 15 ) u3 + 3 ( 10 - 12 q - p ) u2 + 4 q u + q  if  u [ 0 ; 1 ] 0  otherwise

The function f(u) with parameter p is used as blending function for the approximation, see equation (67).
The function e(u) with parameters p and q is used as blending function for the interpolation, see equation (68).
Equations (69) and (70) show the derivatives of the functions.

When using X-splines in WXD files, equidistant control points with Δt=1 are assumed.
An X-spline is described by n control points with indices in the range from 0 to n1, whereby each control point Pk at time t=Tk is assigned an additional parameter sk with -1sk1.
Points with -1sk<0 are interpolation points. Points with 0sk1 are approximation points; angular points are possible for sk=0.

Each control point Pk has a left-sided blending function Fk- and a right-sided blending function Fk+. These blending functions indicate how strongly the control point affects the course in the adjacent segments. The blending functions each extend over up to 2 segments, so a control point can influence a total of 4 segments.
A curve segment is influenced by the two control points at the segment ends and by their neighbors. The sk value of each control point Pk determines the type and parameters of the right- and left-sided blending functions of the neighboring points (but not of the point Pk itself).

The following applies to approximation points, 0sk1:

(71) T k - 1 + = Tk + sk T k + 1 - = Tk - sk (72) p k - 1 + = 2 ( T k-1 + - T k-1 ) 2 p k + 1 - = 2 ( T k+1 - - T k+1 ) 2 (73) F k - 1 + ( t ) = f ( t - T k-1 + T k-1 - T k-1 + , p k-1 + ) F k + 1 - ( t ) = f ( t - T k+1 - T k+1 - T k+1 - , p k+1 - ) (74) d dt F k - 1 + = 1 T k - 1 - T k - 1 + · r ( t - T k-1 + T k-1 - T k-1 + , p k-1 + ) d dt F k + 1 - = 1 T k + 1 - T k + 1 - · r ( t - T k+1 - T k+1 - T k+1 - , p k+1 - )

Equation (71) shows how far the effective range of the blending functions of the neighboring points extends.
Equation (72) is used to determine the p parameter of the blending function.
The function f(u,p) is used as the right-sided blending function of the left neighboring point and as the left-sided blending function of the right neighboring point, see equation (73).
Equation (74) shows the first derivatives of the blending functions.

The following applies to interpolation points, -1sk<0:

(75) p k - 1 + = 2 p k + 1 - = 2 (76) q k - 1 + = - sk 2 q k + 1 - = - sk 2 (77) F k - 1 + ( t ) = e ( Tk - t , p k-1 + , q k-1 + ) F k + 1 - ( t ) = e ( t - Tk , p k+1 - , q k+1 - ) (78) d dt F k - 1 + = - s ( Tk - t , p k-1 + , q k-1 + ) d dt F k + 1 - = s ( t - Tk , p k+1 - , q k+1 - )

Equations (75) and (76) are used to calculate the parameters p and q for the blending functions of the neighboring points.
The function e(u,p,q) is used as the right-sided blending function of the left neighboring point and as the left-sided blending function of the right neighboring point, see equation (77).
Equation (78) shows the first derivatives of the blending functions.

After the functions Fk- and Fk+ have been defined for all points Pk, curve points and first derivatives of the coordinates can be calculated for each curve segment with start point Pi and end point Pi+1 using:

(79) zx ( t ) = x i-1 · F i-1 + ( t ) + x i · F i + ( t ) + x i+1 · F i+1 - ( t ) + x i+2 · F i+2 - ( t ) (80) zy ( t ) = y i-1 · F i-1 + ( t ) + y i · F i + ( t ) + y i+1 · F i+1 - ( t ) + y i+2 · F i+2 - ( t ) (81) n ( t ) = F i-1 + ( t ) + F i + ( t ) + F i+1 - ( t ) + F i+2 - ( t ) (82) zx' ( t ) = d zx d t = x i - 1 · d dt F i-1 + (t) + x i · d dt F i + (t) + x i + 1 · d dt F i+1 - (t) + x i + 2 · d dt F i+2 - (t) (83) zy' ( t ) = d zy d t = y i - 1 · d dt F i-1 + (t) + y i · d dt F i + (t) + y i + 1 · d dt F i+1 - (t) + y i + 2 · d dt F i+2 - (t) (84) n' ( t ) = dn dt = d dt F i-1 + (t) + d dt F i + (t) + d dt F i+1 - (t) + d dt F i+2 - (t) (85) x ( t ) = zx (t) n ( t ) (86) y ( t ) = zy (t) n ( t ) (87) x' ( t ) = dx dt = n ( t ) · z x ' ( t ) - zx ( t ) · n' ( t ) n2 ( t ) (88) y' ( t ) = dy dt = n ( t ) · z y ' ( t ) - zy ( t ) · n' ( t ) n2 ( t )

For open splines, the first summand for the first segment and the last summand for the last segment are omitted in equations (79…84).
To simplify the calculation program, each X-spline segment is placed in an arrangement with four points A, B, C, and D so that the control point for the start of the segment is at B and the control point for the end point of the segment is at C. A then corresponds to the “left” neighboring control point, D to the “right”.

Approximation of X-splines by Bezier splines

The output formats provided by wxd2lat support Bezier splines. It is necessary to approximate X-splines using Bezier splines.
First, curve points are calculated that correspond to the control points (t=T1, t=T2…). To calculate the control points for the Bezier splines, the derivative in the curve points is required. As X-splines can have angular points in the curve points that correspond to the control points, both a “left-sided” and a “right-sided” derivative are calculated.
X-splines are fifth-degree curves and therefore differ from third-degree Bezier splines. It makes sense to represent each X-spline segment by several Bezier spline segments.
For this purpose, curve points and derivatives are also calculated between the curve points calculated in the previous step. No angular points can occur here, so it is sufficient to calculate the derivative once in each point.
If each X-spline segment is represented by several (m) Bezier spline segments, the slopes must be corrected. Bezier splines start and end at t=0 and t=1. However, the slopes calculated so far refer to areas with t=ts and t=ts+1m. Using the calculated curve points as the start and end points of Bezier splines corresponds to a stretching along the t axis by the factor m. This is accompanied by a reduction in the slope, so all previously calculated derivatives must be corrected by dividing them by m.

Length calculation on splines

The length calculation for X and Bezier splines or spline segments is approximated in wxd2lat. For this purpose, the spline is divided into intervals with even t steps and the points are calculated for the interval boundaries. The distances between these points are added up.
In each pass, the number of intervals is doubled until the change in the sum from one pass to the following pass falls below the desired accuracy limit.

Length correction for arrowheads

Length correction on splines is relatively difficult, as the formulas cannot be analytically rearranged to obtain a t for a given distance to the end point.
To determine a t for which the length from the associated point to the end of the spline has the specified value s, an iterative method (Regula falsi modified according to Anderson-Björck) is used. First, it is checked whether s is smaller than the total length of the spline. If so, the t for the first point (0) and the final point (n-1) are used as starting values for the interval limits.


Literature

〈BS1995〉
Carole Blanc, Christophe Schlick:
X-Splines: A Spline Model Designed for the End-User
Proceedings of the SIGGRAPH 1995
← Previous ↑ Home → Next

Related

Wiki: wxdkdraw

MongoDB Logo MongoDB