which api for shapes such as ellipses, bezier...?

hi, sorry in advance for bad language, not that good at english nor programming, so i’m having trouble expressing myself explicitly regarding to the programming issues =)

me and some mates are doing this school project, where we are supposed to develop some software in which the user should be able to place shapes such as:

  • circles & ellipses, closed or open (like a pie missing one piece of pie =), without the lines from circle centre to the border )
  • bezier curves
  • straight lines
  • parabolas

… into a 2-dimensional plane.

these shapes will be given a certain height, and both sides (of the shape, inside/outside) will be given different parametres regarding to absorption og diffusing (dont know if these are the english word for it) of the surfaces.

further on, we are supposed to render this into a 3d-picture, showing some advanced caustics.

the display of these caustics is the main point of the software, as the user of the software wants to get the specific measures of these shapes, so that they can reproduce this setting and caustics in real life. ( they are artists of some kind)

only thing we DO know, is that the GUI will be programmed in Java.

We’ve found several helpful classes in the Graphics2D for modelling 2d-shapes, but cant seem to find any way to get these shapes into a Java3D context…

So: IS there a way to do it by the help of Graphics2D shapes?

We’ve looked into the Java3D API as well, but there seem to be little or none classes that could help our “shaping needs” in such a way as Graphics2D can…

Or is it?

Finally, if the answer to the 2 questions above is NO; which API would you recommend for us?

Or do you have any other ideas?

thanks in advance,

lars petter
NORWAY

There aren’t any prewritten classes to do this on your behalf, but it should be easy enough to find the maths to do them for yourselves. Java3D and the Graphics2D APIs don’t really talk very well to each other in terms of geometry, although they are fine for passing images back and forth.

Java3d is the most high level 3D java api and so it will probably be easier for you to implement stuff using it than using one of the direct OpenGL ones, but you will probably have to work effectively from scratch whichever you use.

The shapes that you want to draw are Beziers (4 control points) or general NURBS?? I have a program that renders Beziers curves and surfaces, (the algorithm for the surfaces has errors).
For the curves I evaluate a set of points and use Lines for the Geometry… The same method can be used to calculate the points in a ellipses or the others shapes needed…

I have the code in my home (now I’m at work), I can post the bezier code as an example.

I don’t understand well, what will you do with the curves after… setting height and sides. Render into 3d.
The final image has the profile of a hill, mountain??

Rafael

Is it possible for you to post the code for the curves…

Cheers

hi again, thanks for the responses

[quote]The shapes that you want to draw are Beziers (4 control points) or general NURBS??
[/quote]
i’m not sure what NURBS are, so i cant answer that=)

an example:

in the 2d plane, i want to place a circle, assign a height to it, place a light source, and then get a rendered image, including the caustics. like this:

http://usurped.net/renders/caustics.jpg

it’s these lighting effects that are the main point.

we’ve been thinking of using java3d in the 2d-plane as well, since that would make it much easier for us to get the 3d render done. the problem is then, how we easily can get the shape modelling done.

the modelling is supposed to be somewhat like how you do it in adobe illustrator, with the bezier curves, you add start & end point as well as control points, and these should be draggable. the rotate/move/scale funtionality from illustrator is also desirable.

hope this clears things up a bit.

EDIT: i’m also wondering if java3d supports such a detailed level of lighting/shadowing effects. can i get something as detailed as in the picture i linked?

  • lars petter

Woa! Nice lightning…
But I don’t think you could get this efects woth Java3D (maybe one of the OpenGL bindings). The shading model in Java3D hasn’t shadows…
Other option is to program your won methods for raytracing/rendering in Java2d/awt.

For the GUI, I recomend to use 2 frames/panels, one with the drawing in 2D sharing the model with the 3d display(which also knows how to extrude de shape from 2d to 3d)
In the drawing panel you can listen the mouse events to edit your shapes. And the 3d display will update its contents(it can be automatically or manually).

Ask in the Jogl or LWJGL forums to know if there is a possibility to achieve what you want…

Rafael

i’ve just been asking around… and what we need is not supported by opengl nor directx… so what we’ll be doing is (like you are suggesting) using a raytracer, probably povray (www.povray.org), exporting povray “code” from the 2d plane.

however, thanks for the help, we really appreciate your effort. now, off to read povray documentation:)

  • lars petter

Try visiting this website and have a look at the chapter for lathe shapes. It might be of interest

http://fivedots.coe.psu.ac.th/~ad/jg/

esxvm, there goes the code, it subdivides the curve until the distance of the fitst to points is less then the parameter.
The code has spanish comments, (almost all the vars and methods are in english)…

import javax.media.j3d.*;
import javax.vecmath.*;

public class Curva {
  BranchGroup BG;
  public Curva(Point3d[] elem,Appearance ap,double prec) {
    BG = new BranchGroup();
    Shape3D[] r = generatePatchs(elem,ap,prec);
    for(int i=0;i<r.length;i++)
      BG.addChild(r[i]);
  }
  public BranchGroup getBG(){
    return BG;
  }
  Shape3D[] generatePatchs(Point3d[] v,Appearance ap,double dst){
    if(v[0].distance(v[1])<dst  || v[2].distance(v[3]) < dst){
      Shape3D[] res = new Shape3D[1];
      Point3d[] d = new Point3d[6];
      d[0]=v[0];
      d[1]=v[1];
      d[2]=v[1];
      d[3]=v[2];
      d[4]=v[2];
      d[5]=v[3];
      res[0]=new Shape3D();
      LineArray qa=new LineArray(6,QuadArray.COORDINATES);
      qa.setCoordinates(0,d);
      res[0].setGeometry(qa);
      res[0].setAppearance(ap);
      return res;

    }
    else{
      Point3d tmp = new Point3d(v[1]);
      tmp.add(v[2]);
      tmp.scale(0.25);
      //primero v1;
      Point3d[] v1 = new Point3d[4];
      v1[0] = new Point3d(v[0]);
      v1[1] = new Point3d(v[0]);
      v1[1].add(v[1]);
      v1[1].scale(0.5);
      v1[2] = new Point3d(v1[1]);
      v1[2].scale(0.5);
      v1[2].add(tmp);

      //luego v2
      Point3d[] v2 = new Point3d[4];
      v2[3] = new Point3d(v[3]);
      v2[2] = new Point3d(v[2]);
      v2[2].add(v[3]);
      v2[2].scale(0.5);
      v2[1] = new Point3d(v2[2]);
      v2[1].scale(0.5);
      v2[1].add(tmp);
      
      //falta la union, v1[3], v2[0];
      
      v1[3] = new Point3d(v1[2]);
      v1[3].add(v2[1]);
      v1[3].scale(0.5);
      
      v2[0] = new Point3d(v1[3]);
      
      Shape3D[] r1 = generatePatchs(v1,ap,dst);
      Shape3D[] r2 = generatePatchs(v2,ap,dst);
      Shape3D[] res = new Shape3D[r1.length+r2.length];
      int j=0;
      for(int i=0;i<r1.length;i++){
        res[j+i]=r1[i];
      }
      j+=r1.length;
      for(int i=0;i<r2.length;i++){
        res[j+i]=r2[i];
      }
      return res;

    }
  }
}

It receives the four control points, the appearance and the minimum distance.
To add it in the scene use getBG() returns a branchgroup with the Shape inside.