next up previous contents index
Next: Drawing Up: Creating and Drawing Objects Previous: Creating and Drawing Objects   Contents   Index

Geometric Data Structures

The simplest object in the world is a point, represented by an ordered triple of real numbers (double-precision floats). The function P(x1,x2,x3) creates the point  $ (x_1,x_2,x_3)$. If only two arguments are provided, $ x_3=0$ by default. This convention allows ePiX to treat 2- and 3-dimensional figures uniformly. Often points are given names, so they can be used repeatedly throughout a figure. The (essentially equivalent) commands

  P pt(x_min, 2*x_min, 4);
  P pt = P(x_min, 2*x_min, 4);
create a point named pt and initialize it to  $ (x_\mathrm{min},2x_\mathrm{min},4)$, using the current value of  $ x_\mathrm{min}$. This value is used each time pt occurs subsequently. In general, an expression involving variables may be used to assign a value to a data structure (not just a point). However, a variable cannot be used until a value has been assigned. For example, the commands above will not work before the bounding box is set, since the value of  $ x_\mathrm{min}$ is unknown. Further, changing the value of a variable does not ``update'' the values of dependent data structures.

Points can be given in polar, cylindrical, or spherical coordinates; all arguments are numerical.

  P pt=polar(r, t);  // (r*Cos(t), r*Sin(t))
  P pt=cyl(r, t, z); // (r*Cos(t), r*Sin(t), z)
  P pt=sph(r, t, phi);
The arguments of sph are radius (distance to the origin), longitude (measured from the $ x_1$-axis), and latitude (measured from the equator). By default, angles in ePiX are measured in radians. Two other ``angular modes'' are available: degrees and revolutions. The angular mode is set with an identically-named command, e.g., degrees(), and all trigonometric operations are affected.

ePiX provides algebraic operations on triples, including addition, scalar multiplication, the dot and cross products, and a few others. These operations are used to express relationships between triples, as in

  P p1(2,1), p2(-3,1);
  P q1 = p1-p2, q2 = 2*p1-3*p2, q3=q1*q2;
The points $ q_1=p_1-p_2$, $ q_2=2p_1-3p_2$, and  $ q_3=q_1\times q_2$ could be given hard-coded values. However, defining their values symbolically imbues the figure with logical structure, making the file easier to read, modify, and maintain. The standard basis is available: E_1=P(1,0,0), etc.

Practically, ordered triples of numbers are used to represent both locations (points) and displacements (vectors). Mathematically, the concepts are distinct; for example, it makes geometric sense to add two displacements (obtaining a displacement), or to add a displacement to a location (to get a location), but two locations cannot be added meaningfully. Algebraic operations act on vectors, not points. ePiX does not enforce the distinction between points and vectors, but will in The Next Generation.

ePiX implements data structures that represent line segments, circles, planes, and spheres. These structures can be translated, scaled, and intersected. A code snippet illustrates basic techniques:

  circle C1(P(0,1), P(0,-1), P(0.5,0)); // circle through 3 pts
  C1 += P(0.1,0);           // translate center
  C1 *= 2;                  // double the radius

  sphere S1(P(0,0,0), 1.5); // sphere of radius 1.5 at origin
  plane P1(P(0,0,0), E_3);  // (x,y)-plane
  circle C2 = S1*P1;        // circle of intersection
Use of these data structures is explained in more detail in Chapter 3.


next up previous contents index
Next: Drawing Up: Creating and Drawing Objects Previous: Creating and Drawing Objects   Contents   Index
Andrew D. Hwang 2004-09-04