Re: Point in Triangle

Hi Desiree,

The method valueToTri of Irregular2DSet does what you want.  Given
an array of samples, valueToTri returns an array of indices into the
Irregular2DSet's triangles.  Unfortunately, valueToTri is marked
private right now.  I will change the method to public for the next
VisAD release, but in the meantime, you should be able to change it
yourself and recompile without any ill effects.

After marking valueToTri as public, something like the following
should work for you to find the containing triangle for a sample
(or list of triangles for multiple samples):

//---------------

// construct Irregular2DSet
float[][] samples = new float[][] {eastValues, northValues});
Irregular2DSet set = new Irregular2DSet(xy, samples);

// allocate array for sample for which containing triangle is desired
float[][] samp = new float[2][1];
samp[0][0] = x_coord; // x coordinate of sample
samp[1][0] = y_coord; // y coordinate of sample

// determine containing triangle
int[] indices = set.valueToTri(samp);
int[] tri = set.Delan.Tri[indices[0]];

// output values of triangle vertices
for (int i=0; i<tri.length; i++) {
  System.out.println("Triangle " + (i + 1) + ":");
  for (int j=0; j<2; j++) System.out.print(" " + samples[j][tri[i]]);
  System.out.println();
}

//---------------

-Curtis

At 09:16 2/22/01, you wrote:
>Hi,
>
>I have a given set of 3D-point and the x,y-coordinates of one point
>somewhere in my set of points. I
>want to interpolate the height of the point. 
>I want to add this point in my set and use the Delaunay-Triangulation of
>VisAD. 
>Without this extra point the Delaunay Triangulation is working fine.
>
>RealType x = RealType.getRealType("x");
>        RealType y = RealType.getRealType("y");
>        RealType height = RealType.getRealType("height");
>        try {
>            RealTupleType xy = new RealTupleType(x, y);
>            FunctionType terrain_type = new FunctionType(xy, height);
>            Irregular2DSet set = new Irregular2DSet(xy,new float[][]
>{eastValues,northValues});
>            FlatField terrain = new FlatField(terrain_type, set);
>            terrain.setSamples(new float[][] {heightValues});
>                    
>            display = new DisplayImplJ3D("display1");
>            ScalarMap hoxmap = new ScalarMap(x, Display.XAxis);
>            ScalarMap reymap = new ScalarMap(y, Display.YAxis);
>            ScalarMap heightmap = new ScalarMap(height, Display.ZAxis);
>                    
>            display.addMap(hoxmap);
>            display.addMap(reymap);
>            display.addMap(heightmap);
>                
>            hoxmap.setRange(-1.0, 1.0);
>            reymap.setRange(-1.0, 1.0);
>            heightmap.setRange(-1.0, 1.0);
>            
>            DataReferenceImpl data_ref = new
>DataReferenceImpl("data_ref"); 
>            data_ref.setData( terrain );
>            renderer = new DefaultRendererJ3D();
>            display.addReferences(renderer,data_ref);
>            display.addDisplayListener(listener);
>        }
>        catch (VisADException ve) {
>            System.out.println("VisAd TupleType Exception");
>        }       
>        catch (RemoteException re) {
>            System.out.println("RemoteExcpetion");
>        }
>
>How can I find the triangle in which the point belongs to?
>Are there some standard geometric algorithms to achieve that?
>Where do I have to look at.
>
>Thanks for your help in advance
>
>Desiree
>
>
>
>o------------------------------------------------------------------------o
>| Desiree Hilbring      Institut fuer Photogrammetrie und Fernerkundung  | 
>|                       Universitaet Karlsruhe, Germany                  |
>|                                                                        |
>|                       email: hilbring@xxxxxxxxxxxxxxxxxxxx            |
>|                       # 0721 6083676                                  |
>o------------------------------------------------------------------------o


  • 2001 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: