| ← Previous | ↑ Home | → Next |
German version available: Technische Details zu wxdkdraw und wxd2lat
The following requirements were formulated when designing the file format and the wxdkdraw and wxd2lat programs:
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.
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
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
to ensure that the magnetic grid points lie on integer coordinates even if the magnetic grid interval is reduced by a factor of or .
All three factors are used to calculate the WXD resolution:
The WXD file format uses a resolution of 16256000 wxd units per inch.
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 P1…P0…P2 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:
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 according to equation 11 with a tolerance according to equation (12).
The following formulas are used for length correction on the final segment with penultimate point and final point if the second step results in a positive value:
The final segment is drawn from point to point .
The following equations apply to an arc with center and radius given by three consecutive points
This system of equations (17,18,19) can be solved for , and .
The solutions for and are shown below in equations (20) and (21). The solution for is relatively complicated. It is easier to determine by substituting and into one of the equations above.
We have to take care of the following special cases:
The vector product is considered to check for the special cases. Since , and only have x- and y components, the vector product only has a z component:
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. , and cannot be calculated.
If a circular arc from to is given by the radius and the angle and is to be shortened so that the distance between the new end point and the old end point is , the angle shortening can be calculated as follows:
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.
For calculations on rotated ellipses, a formula for the distance of a point to a straight line through the coordinate origin with the angle is required.
Equation (28) applies to the straight line:
For the distance between and a straight line point given by , equation (29) applies:
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.
For the apparent solution 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.
To determine the bounding box of an ellipse rotated by , the height of the highest point and the width of the point furthest to the right are required.
In the left-hand diagram, is the upper horizontal tangent, is the right-hand vertical tangent. The height is the distance between the point of contact and the -axis. The width is the distance between the point of contact and the -axis.
For the calculation, the entire arrangement is rotated back by , the ellipse is aligned with the axes again. The straight lines and are no longer parallel to the axes. The auxiliary lines and are obtained from the rotation of the axes. The height is now the distance from the point to the auxiliary line (formerly -axis). The width is now the distance from the point to the auxiliary line (formerly -axis).
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 , this direction vector must have the angle according to equation (35).
This can be converted to equation (36) to determine .
Similarly, the direction vector for point must have the angle .
This means that can be determined using equation (38).
Using and , we can calculate and .
The height of the rotated ellipse is now the distance from the point to the straight line through the coordinate origin with the angle .
The width of the rotated ellipse is now the distance from the point to the straight line through the coordinate origin with the angle .
The following applies to the bounding box of a rotated ellipse with center in the coordinate origin:
If the center of the rotated ellipse is not at the coordinates origin, the bounding box also shifts accordingly.
Curves in can be described by equation:
In the field of computer graphics, is often used for the entire curve or for a curve segment.
A spline describes a continuous curve by a set of discrete values.
For cubic Bezier splines, each segment is described by start point and end point as well as two control points and .
denotes the control point “to the right” of the start point. denotes the control point “to the left” of the end point.
In the literature, the notation and is often used for the start and end points and and or and for the control points.
The segment is traversed with the parameter in the interval , 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.
To determine the bounding box of a Bezier spline segment, extreme points of the x and y values for must be taken into account in addition to the start and end points.
Equation (50) shows the calculation of the coordinate as a function of .
This calculation can be simplified to a polynomial of , the coefficients … 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 , there are 2 extreme points corresponding to equation (57).
If equation (51) is a quadratic polynomial with and , there is only one extreme point.
If both and , the line is straight and there are no local extrema.
For the local extreme points with , 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.
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 , 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 and curves. However, the main aim of the approximation is to achieve the best possible approximation to the desired --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.
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 , but by a still unknown coefficient .
This coefficient must be selected so that the center of the Bezier segment has the distance 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]));
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.
The function with parameter is used as blending function for the approximation, see equation (67).
The function with parameters and 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 are assumed.
An X-spline is described by control points with indices in the range from 0 to , whereby each control point at time is assigned an additional parameter with .
Points with are interpolation points. Points with are approximation points; angular points are possible for .
Each control point has a left-sided blending function and a right-sided blending function . 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 value of each control point determines the type and parameters of the right- and left-sided blending functions of the neighboring points (but not of the point itself).
The following applies to approximation points, :
Equation (71) shows how far the effective range of the blending functions of the neighboring points extends.
Equation (72) is used to determine the parameter of the blending function.
The function 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, :
Equations (75) and (76) are used to calculate the parameters and for the blending functions of the neighboring points.
The function 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 and have been defined for all points , curve points and first derivatives of the coordinates can be calculated for each curve segment with start point and end point using:
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 , , , and so that the control point for the start of the segment is at and the control point for the end point of the segment is at . then corresponds to the “left” neighboring control point, to the “right”.
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 (, …). 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 () Bezier spline segments, the slopes must be corrected. Bezier splines start and end at and . However, the slopes calculated so far refer to areas with and . Using the calculated curve points as the start and end points of Bezier splines corresponds to a stretching along the axis by the factor . This is accompanied by a reduction in the slope, so all previously calculated derivatives must be corrected by dividing them by .
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 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 on splines is relatively difficult, as the formulas cannot be analytically rearranged to obtain a for a given distance to the end point.
To determine a for which the length from the associated point to the end of the spline has the specified value , an iterative method (Regula falsi modified according to Anderson-Björck) is used. First, it is checked whether is smaller than the total length of the spline. If so, the for the first point (0) and the final point (n-1) are used as starting values for the interval limits.
| ← Previous | ↑ Home | → Next |