"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <jge159$mbo$1@newscl01ah.mathworks.com>...
> "Nic Roberts" wrote in message <jgdtsa$cnt$1@newscl01ah.mathworks.com>...
> > Hi,
> >
> > I have an STL file which I can read in so that I get face number, coords of each face (triangle) and the normal vector for each face. The faces form a closed volume.
> >
> > I would like to create a 3D matrix representation of this volume, with matrix elements representing either inside the volume or outside the volume.
> >
> > So my question is how do determine if a given coordinate is inside the volume or not?
>
> For a point P: (x,y,z) count the number n of triangle face {Ti} such that
>
> 1. (x,y) inside the projection of {Ti} on xy plane (use Tseach function for that)
> 2. zi > z, where zi is coordinate that Ti meat the line { (x,y,t) t in R } (simple linear algebra).
>
> P is inside the volume if the number n is odd, P is outside otherwise.
>
> Bruno
       
Another method might be to use outward pointing normals to calculate the signed solid angle projected by each triangle onto a given point (x,y,z). The algebraic sum of these should be 4*pi if (x,y,z) is interior and 0 otherwise.
Roger Stafford
