This browser does not have a Java Plug-in.
Get the latest Java Plug-in here.

anar+

by   LaBelle + Nembrini
©2008

built with ( )
   examples index
Rotate: middle click or key[1]
Zoom in|out: wheel button or key[2]
AutoRotate: key[5]
(First Click inside the applet to enable keys)

This applet use OpenGL, you might have to install extra jogl libraries once to view this applet. You may have a look at image capture and video at the bottom of this page. You might accept security security permenently to remove the security prompts on each pages.



sourcecode


   PDE Download:   Test04bVoronoi.pde
   JAVA Download:   Test04bVoronoi.java


Click on anar+ terms to get the documentation.

import processing.opengl.*;
import anar.*;
 
 
 
import java.util.*;
 
import voronoi.*;
 
 
/*
 * Example for Anar library by Guillaume LaBelle + Julien Nembrini
 * http://anar.ch
 */
 
 
Obj myObj;
 
void setup(){
    size(800,400,OPENGL);
  Anar.init(this);
  Anar.drawAxis();
 
  initForm();
}
 
void initForm(){
  myObj = new Obj();
 
  // RANDOMS POINTS
  Obj inPts = new Obj();
  for (int i = 0; i<200; i++)
    inPts.add(Anar.PtRnd(400,400));
 
  myObj.add(inPts);
 
 
  // INIT THE TRIANGULATION
  int sz = 1000000;
 
  Simplex firstTriangle = new Simplex(new Pnt[]{new Pnt( -sz, -sz), new Pnt(sz, -sz), new Pnt(0,sz)});
  DelaunayTriangulation dt = new DelaunayTriangulation(firstTriangle);
 
  // ADD THE POINTS
  for (int i = 0; i<inPts.numOfPts(); i++)
    dt.delaunayPlace(new Pnt(inPts.pt(i).x(),inPts.pt(i).y()));
 
 
  // RETURN EDGES
  Pts allPts = new Pts();
 
  ArrayList simplexComparator = new ArrayList();
 
  for (Iterator it = dt.iterator(); it.hasNext();){
 
    Simplex triangle = (Simplex)it.next();
 
    for (Iterator otherIt = dt.neighbors(triangle).iterator(); otherIt.hasNext();){
 
      Simplex other = (Simplex)otherIt.next();
 
      // CHECK IF ALREADY IN THE LIST
      Simplex[] ss = new Simplex[2];
      ss[0] = triangle;
      ss[1] = other;
 
      if( !isInList(simplexComparator,ss)){
 
        // ADD REVERSED TO THE LIST
        Simplex[] ss2 = new Simplex[2];
        ss2[0] = other;
        ss2[1] = triangle;
        simplexComparator.add(ss);
        simplexComparator.add(ss2);
 
        Pnt p = Pnt.circumcenter((Pnt[])triangle.toArray(new Pnt[0]));
        Pnt q = Pnt.circumcenter((Pnt[])other.toArray(new Pnt[0]));
 
        Pts connex = new Pts();
        connex.add(filterPts(allPts,p.coord(0),p.coord(1)));
        connex.add(filterPts(allPts,q.coord(0),q.coord(1)));
 
        myObj.add(connex);
      }
 
    }
  }
 
}
 
 
// COMPARE SETS OF SIMPLEXS
boolean isInList(ArrayList arr, Simplex[] ss){
  boolean out = false;
 
  for (int i = 0; i<arr.size(); i++){
    Simplex[] sss = (Simplex[])arr.get(i);
    if(sss[0]==ss[0]&&sss[1]==ss[1]){
      out = true;
    }
  }
  return out;
}
 
 
// MAINTAIN A LIST OF UNIQUE POINTS
Pt filterPts(Pts pts, float x, float y){
  Pt out = Anar.Pt(x,y);
 
  for (int i = 0; i<pts.size(); i++){
    Pt q = pts.pt(i);
 
    if(Math.abs(q.x()-x)<0.0001&&Math.abs(q.y()-y)<0.0001)
      out = q;
  }
 
  return out;
}
 
 
void draw(){
  background(255);
  myObj.draw();
}
 
void keyPressed(){
  if(key==' ')
    initForm();
}
 
 



screenshots