Dear All,

I have written a Delaunay triangulation 10 years ago 
in C based on triangle structure.
It was 400 lines, so it seems to be a fine task to turn into python.


My problem is the translation of the C structure and the OO thinking.
I tried to draft it so.


/*
The triangle, its neighbours,
    sides and rotations.
 
           0
         VTOP
        /    \ 
       / t  r \
  LEFT/ o    o \RIGHT 1
     / r      t \
    /       act    \
1 VLEFT--------VRIGHT 2
        BOTTOM
           0
*/

typedef struct{
 TRIINDEX    neighbour[3];  // triangles: bottom, right, left
 POINTINDEX  vertex[3];     // vertex: top, left, right
 float       height;        // elevation
} TRIANGLE;


Each triangle has three vertices and three neighbours.
To calculate the elvation on the triangulation at a given point,
it is important to find the coresponding triangle as fast as possible,
so the triangles had directions. But it was important in the update 
process too.
So I had an array with the triangles, but the neighbours were
directed triangles not simple triangle (TRIINDEX).

There were C macros to get the neighbours of the triangles.
To get the left triangle tleft = LEFT(t), tright = RIGHT(t), tbottom = 
BOTTOM(t)

ROT(t) was the same triangle as t, but rotated ccw.
so t = ROT(ROT(ROT(t)))
TOR(t) was the same triangle as t, but rotated cw.
t = TOR(TOR(TOR(t)))

In C, I have used 
typedef unsigned int    TRIINDEX;
to identify a triangle, where the last two bites were used to handle the 
directions.

## I can translate it into python in this way
class Triangle:
    def __init__(self, points, neighbours):
        self.points = points
        self.neighbours = neighbours

      def TOR(self, direction):
        return (self, (direction+1)%3)

      def ROT(self, direction):
        return (self, (direction+2)%3)

      def RIGHT(self, direction):
        return (self.neighbours[(direction+2)%3])
 


I would ask your opinions to encapsulate a triangle into a directed 
triangle.
I made my first trial on the way to keep a directed triangle as a tuple 
(triangle, direction)
and register it in that way.
I would like to use directed triangles, but wouldn't like to use too much 
memory.




Yours sincerely,
Janos Juhasz
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to