[Tutor] Triangle structure for triangulation

János Juhász janos.juhasz at VELUX.com
Thu Aug 30 22:18:36 CEST 2007


Dear Allan,

thanks for your coments.

> > ## 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'm not totally sure what you are looking for but my first
> guess would be to add a direction argument to the init
> and store it as an attribute. But it sounds like you need
> to add some methods too. What do you do with these
> triangles? From your descriptionI'd expect to see some
> methods taking other triangles as arguments?

The triangulation would be used for surface modelling.
The most important function is CalcZ(point(x, y)), that interpolates the
elevation on the surface of a triangle.
For this interpolation I have to find the corresponding triangle of the 
point,
that can be made the fastest by walking from triangle to triangle.
This is the first reason I need the neighbours.

I also need to extend and update the triangulation, when a new point 
inserted into it.

> For example you store the points but never use them.
> Attributes in a class shjould be thee to support the metjods.
> If the atrributes are not used by any method that implies
> that they are not needed or that you are accessing them
> from some function outside the class, which is probably
> an indication of bad OO design.

I feel that, the best would be to strore 3 separate triangles for A,B,C 
points,

Triangulation.Append(Triangle(A,B,C))
Triangulation.Append(Triangle(B,C,A))
Triangulation.Append(Triangle(C,A,B))
And register the topological relations after it. It could be OO, and 
simple.


As I wrote, I made it in C with structures, so it wasn't OO, but fast.
I can translate a C iteration over C structures into python,
to iterate over class objects, and usually I don't miss the pointers.
Except now, when the algorithm based strongly on pointers and indeces :(


Yours sincerely,
Janos Juhasz


More information about the Tutor mailing list