Version 15 of Geometry

Updated 2002-01-24 19:39:20

Arjen Markus This page will describe the geometry package Christian Heide Damm started and that we are now developing in cooperation.

The idea is simple - define points, vectors, planes, lines, line segments and so on via "qualified" lists. Define operations on these lists like, calculate the distance between points, project a line on a plane.

Such a package is useful for applications involving interactive design/drawing, "CAD"-like applications, ...

The page should describe:

  • What objects do we want?
  • Representation of these objects as lists
  • Operations on these objects

AK: Conversions of such objects into other formats ? POVRay for example ? Is the stuff 2D or 3D ?

Arjen Markus At the moment: we simply want to outline the functionality, but conversions may become a part of that! Thanks for the suggestion. The ideas should not be limited to 2D or 3D, but be (as far as practical) independent of the number of dimensions. (The daring among us can then use it for multidimensional data analysis).

AK: Regarding multidimensional data analysis ... There is a linear algebra package out there. By Hume Integration Ltd. [L1 ]. I remember that someone presented a Tensor package at the last Tcl conference (OSCON'2001 San Diego [Refer to wiki page of this one]. Could also tie into tcllib/matrix.

Regarding conversions note that I am working on a module to read and write FIG streams. See http://www.xfig.org/ . I have the basic functionality ready, but want to add a more convenient layer on top.

Arjen Markus Interesting, can you send me some specifications?

AK Sure, when I am home again.


The geometry package should include the following types of "objects":

  • point - characterised only by its coordinates
  • vector - ditto, conceptually quite different from a point object
  • line - a straight, infinite line through a point along some vector
  • plane - a flat surface passing through a point and perpendicular to a certain vector (the normal)
  • linesegment - a straight piece of a line, between two points. AK: Note alternate representation by starting point and a length vector.
  • polyline - a set of connected linesegments, therefore defined by two or more points. (actually a linesegment is two-point polyline). AK: Alternate representation by starting point and list of vectors from point to next point.
  • sphere - characterised by a point (the centre) and the radius
  • wireframe - a set of linesegments not necessarily connected
  • pointset - a set of points without any ordering

There could be more types, such as a prism to characterise, say, a rectangular block or a solid body defined by faces (a facetted body). The above list is, however, quite enough to get started.


The internal representation of, say, a point is very simple: A point is a list like

    {POINT {...}}

where "POINT" indicates the type and the second element is a list of coordinates. This second element can contain any number of coordinates, the number defining the dimension of the space in which it exists.

For vectors we then have:

    {VECTOR {...}}

and for lines:

    {LINE {POINT {...} {VECTOR {...}}

A plane is defined likewise:

    {PLANE {POINT {...} {VECTOR {...}}

Some notes:

  • By using ordinary variables to store these lists, we do not have to worry about cleanup procedures. The geometrical objects exist as long as the variables exist.
  • Both planes and lines should preferrably contain a normalised vector, rather than an arbitrary one. This will make calculations much simpler.

To illustrate the use, consider the following fragment (namespaces have been left out deliberately):

   set point1 [point {1 1 1 1}]
   set point2 [point {1 2 1 -1}]
   set plane1  [plane $point2 [vector {1 0 3 1}]]
   puts "Distance between the points: [calculateDistance $point1 $point2]
   puts "Distance between point and plane: [calculateDistance $point1  $plane1]

In the calculation of the distance between two points, the euclidean distance is chosen. In the calculation of the distance between the point and the line, the formula below is useful:

distance = | (p1 - p2).v1 |

where:

p1 - the vector from the origin to point1

p2 - the vector from the origin to point2

v1 - the vector normal to the plane (with length 1, hence normalised)

x.y - the inproduct of two vectors

.| - the absolute value

We can easily calculate the orthogonal projection of the point (point1) on the plane:

p3 = p1 - distance * v1

or the reflection of the point:

p3 = p1 - 2 * distance * v1


Special cases: 2D and 3D space

For drawing applications, 2D objects will be most important whereas computer aided design applications will focus on 3D objects (or, if so-called homogeneous coordinates are used, 4D objects).

Some methods are specific to 2D or 3D:

  • Determining a bounding box is typical for 2D graphics
  • Determining the outproduct of two vectors can only be done in 3D

Of course generalisations are possible, but they occur at a price: more parameters are involved (bounding boxes in 3D become bounding blocks or you need three vectors in 4D space to almost uniquely define the perpendicular vector as with a 3D outproduct).

For these special cases, additional methods should be available.


JCW - The {POINT {...}} etc. notation is gorgeously clean and simple, but how would you deal with representations, other than Tcl lists? Suppose the data is a memory range with consecutive floats (that what C would call an array), how do you deal with it without conversion? If there is always conversion, then this requires far mor memory during use and rules out memory mapped files as mechanism... :o(

Or is there a way to get the best of both worlds? (I'm referring to VKIT, in which I try to find a middle ground)

AK: As a side note this way of constructing type-tagged data is shown in SICP. They also have things to say about varying representations of the same thing. Their example are complex numbers in (x,y) and polar representation (angle,length). This is of course also a way to represent vectors.

Arjen Markus Well, I have contemplating using the same notation for rational and complex numbers, but it does seem to work best when the amount of associated data is fairly small.


The geometry module should include:

  • Orthographic projection from 3D to 2D
  • Stereographic projection from 3D to 2D (perspective drawing)

This will facilitate drawing real-life objects, such as when you use XFIG to create nice but flat pictures of the real world.

(After a first look at Andreas' work on XFIG, I would say that the package we are designing should be more than adequate to represent the vector objects in drawings. This was the main interest if I am not mistaken of Christian as well).


Arjen Markus On the page Power set of a list I mentioned my reasons for being interested in the set of subsets of a given size. I thought it might be one step in solving a problem concerning solids defined like this:

   x     >= 0
   y     >= 0
   z + x >= 0
   x + 2y +3z <= 10

We have four halfspaces (or any number of halfspaces in any number of dimensions), but how can we determine if they together form a finite volume? Clearly, one needs at least N+1 such halfspaces, if N is the dimension of the space we are looking at.

My conjecture for solving this problem is that if we can find a subset of N+1 halfspaces from all the given halfspaces (say M > N) that have the following relation, then the volume defined by all M halfspaces is either empty or it is finite. The condition:

  • N of these halfspaces form an (non-orthogonal) basis, where the normal vectors pointing into the halfspaces are the basis vectors.
  • The remaining halfspace has a normal vector (same definition for the orientation), such that all coordinates as expressed in the above basis are negative.

This can be seen as something quite reasonable, if you just take three lines in the 2D plane, like x>=0, y>=0 and x+ay>=0 (a varying).

I have not tried to prove it, it is slightly more than a hunch.


Category Graphics - Category Mathematics