help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

beginner / data structure help


From: Jeff Abrahamson
Subject: beginner / data structure help
Date: Thu, 16 Jun 2005 12:08:43 -0400
User-agent: Mutt/1.5.9i

I have a question about how best to read and represent some data.

I have an octave function that understands OFF files (descriptions of
polyhedral shapes).  The format of these files begins with a list of
vertices (1..n) followed by a list of faces.  Since different faces
may have different numbers of edges (equivalently vertices), these are
represented by lines that look like this:

    k  a1  a2  a3  ...  ak

First the number of points, then the (integer) index of each vertex
from the vertex list.  So a typical example for a square face might
look like this:

    4 3 4 17 41

I'm reading these in a loop like this (less error checking):

    [points, num] = fscanf(fid, "%d", 1);        # read k
    [vertices, num] = fscanf(fid, "%d", points); # read a1..ak

The matrix vertices gets a column vector of the vertices incident to
the current face.  In the example above, it has value [3; 4; 17; 41].

I'm then storing these things in a cell array.  This is cumbersome,
but I don't know a better way to do it.

Here's my question, in two parts:

1. What I really want to do is store a matrix of triangular facets.
   It's easy to triangulate a polyhedral face, but I don't know in
   advance of reading the face line how many triangles that face will
   have.  (It will have (points-2).)

   I can do this by reading into a cell block, computing how many
   triangles, then allocating a 3xn matrix and filling it in.  This
   seems cumbersome.  Perhaps it's not as bad as I think.
   Conceptually, I just want to append columns to a matrix.

   Is there a better way?

2. When I use this (3xn) face matrix, I will often want to use it with
   indirection to the vertex matrix.  That is, I'll want to do things
   like this:

      for each column (representing a triangle, [a, b, c] )
          u = vertex(a) - vertex(b);
          v = vertex(a) - vertex(c);
          area = cross(u, v) / 2;
          do something with area
      end

   Does octave offer any idioms that make this sort of thing easier
   for me?  I haven't found any, but octave usually seems to
   anticipate my needs pretty well.

3. At the end of my function, I want to pass back the two matrices I
   have computed.  The only way I've found is to use a cell (which
   would fail, I discovered, if I were trying to pass back cells).  Is
   there a more natural way to return two matrices?

Thanks much for any suggestions.

-- 
 Jeff

 Jeff Abrahamson  <http://www.purple.com/jeff/>    +1 215/837-2287
 GPG fingerprint: 1A1A BA95 D082 A558 A276  63C6 16BF 8C4C 0D1D AE4B



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]