Creating an Arc3D object in Java - java

I will be working with an application that will use 3D graphics in Java and I am pretty sure we'll need an arc object in 3D. I've seen some proposed methods on how to do that, one of which entailed creating an Arc2D object and then rotating it in 3D. Not quite sure how to do that because I couldn't find how to rotate a plane in Java 3D, but I imagine I need to use the javax.media.j3d.J3DGraphics2D object.
Regardless, I am wondering if it is worth my time to create an Arc3D object. It will make everyone's life much easier, it makes more sense to simply have an arc in 3D than create an entire drawing plane and then rotating it, and overall it would be a contribution to Java programmers.
My questions are, from your experience, how long does it take to create a new class that works in an existing API? and where would I start? I tried looking at the Graphics, Graphics2D, and Arc2D documentations and couldn't find where the actual drawing takes place so I can see how to do the same in 3D.
Any help?

The 'AWT Shape Extruder' API supports extruding of an Arc2D object in Java 3D. Download is available here: http://www.interactivemesh.org/testspace/awtshapeextruder.html

Related

How do you create and render a 3D Fractal?

So I've been assigned a recursive art project for my AP CS class and have a bunch of spare time, so I've decided to try something a little bit more ambitious.
My plan is to create a 3D fractal, either rendered and shaded in a visualization with GL, or represented via spatially mapping the respective equations' outputs to points on a cube and drawing those. If this explanation seems unclear, please check out the links at the bottom for images. Now, I don't need the fractal to be able to be modified in-program. I just need it to render a single BufferedImage, which I'll be putting directly on a JFrame.
My experience in Java, as far as this project goes, is a bit limited. I've drawn Mandelbrot and Julia set fractals before, but I have little to no experience drawing/rendering objects in 3D in Java. This is all stuff I can look up and figure out myself though, so no worries here.
Thus, the question: How does one map a fractal that should be in the 2nd dimension (e.g. log(no. of subdivided entities)*log(side length of subdivision) = 2) to the 3rd dimension (e.g. log(no. of subdivided entities)*log(side length of subdivision) = 3)? I'm lost trying to mathematically work this out, and I believe there is a more organized approach to go about this circumventing a lot of the math that already exists.
Also, if you are aware of a structured approach to render a 2D fractal, as drawn by a formula, and render it in 3D, provided the respective formula is provided (power is raised), please let me know. I've heard of Ray Tracers, no idea what they are, a brief summary would be cool.
Here are links with pictures of the result I want to obtain:
http://2008.sub.blue/assets/0000/4575/power8_large.jpg
https://www.youtube.com/watch?v=rK8jhCVlCtU
It looks like the image is an example of a Mandelbulb. The is a similar iteration formula to the Mandlebrot set but using 3D points and a novel idea of what raising a 3D point to a power means.

JBox2D - Drawing with DebugDraw

How do you draw elements with JBox2D? I'm fine using the DebugDraw, I just want to find a quick way to do this in Java since I haven't worked much with graphics.
Do I need to use a Canvas? Or a JFrame? And how does the world know when I call
world.drawDebugData()
where to draw it to?
How could I devise a class that just drew points where I want them, and integrate this with JBox2D?
...
while(true)
world.step(timeStep, velocityIterations, positionIterations);
Vec2 position = body.getPosition();
float angle = body.getAngle();
System.out.printf("%4.2f %4.2f %4.2f\n", position.x, position.y, angle);
}
I imagine I could put this code somewhere inside this while loop, but I'm not exactly sure where. Is there a function that's called every time a World steps? Can I put a draw function in there? I'm even ok using the DebugDraw if I could figure it out...
Could you please help me understand what kind of class would take all the objects in the World object and draw them continually? (and where to draw to?)
You can easily create new testbed tests, this is the best way to test out your new physics ideas and not worry about drawing and GUI stuff. It even supports adding extra real-time options. Check it out here:
https://code.google.com/p/jbox2d/wiki/Testbed
It's difficult to know where to organize everything if you're not used to programming games and physics engines.
Dyn4j is another great physics library that has great examples explaining where to put everything and even how the user can interact with the world. A lot about the dyn4j library is identical to box2d/jbox2d, so if you just try out their examples real quick, it will lend a hand to figuring out how to render graphics in box2d.

How to know if a point is inside a complex 3D shape (.ply file)

I'm working on a Java project witch is really killing me. After several days of researching on different forums, looking for what I really need, I come to ask your help.
My data :
A .ply file (containing a 3D shape made of a lot of triangles)
A point (3D coordinates)
I would like to know if this point is contained inside the complex 3D shape.
I have split this problem in 2 smaller problems :
How can I represent the complex 3D shape in memory? (I found several libraries, but it seems really complex for the task I want to do : Java3D, JBullet, JME3...) I do not want my java application to show the object for now.
How can I know if this point is inside the 3D shape or not? (I thought to make a 3D vector starting from the point and to count the number of intersections with the shape, but I don't see how to do and witch library can I use?)
Maybe there are easier ways to do it, that's also why I come to you.
I am really stuck now and I would like if this is possible without writing customs libraries...
(Sorry for my writing, I'm not English ^^)
Thanks for helping me.
Here is one approach. Not the best or the fastest, but once you have something working, it will be easier to improve upon.
How can I represent the complex 3D shape in memory?
Implement a quick and dirty PLY file format parser. Here is the PLY format spec. Load the data up and store it internally: an array for each X, Y, and Z. This is all just plain Java.
How can I know if this point is inside the 3D shape or not?
Define a line based on your point and some other arbitrary point. For each polygon, determine where it intersects the plane (some help) and if the intersection point is inside or outside the polygon (some help). As you suggested, then count the number of intersections to determine if the point is inside or outside your 3d shape.

3d Way Finding Mapping

Hello there guys and gals
I'm just little bit confused about creating simple way finding using the java programming language?
Or is it possible in java? I want to create a simple way finding just like these
Do you have any suggestions for this particular matter?
You need to use a shortest-path algorithm and a matrix-builder from the way-points of your map. Java 3D has built-in primitive shapes such as cylinders, spheres and cubes. But you can make your own geometry from points, triangles and quads. See some of the java3D tagged questions in SO.
In java3D, mouse and keyboard interaction is very easy implemented.
Collision detection is also a good pro of java3D while not having a shadow lib being a con.
You can try 3D Wayfinder. They have a public API and fully featured 3d wayfinding. Its not in Java but uses HTML5, WebGL and JavaScript. Yiu have to upload just a floor plan model and are good to go.

How to create 3D Tag Cloud in Java

I need a suggestion/idea how to create a 3D Tag Cloud in Java (Swing)
(exactly like shown here: http://www.adesblog.com/2008/08/27/wp-cumulus-plugin/)
, could you help, please?
I'd go either with Swing and Java2D or OpenGL (JOGL).
I used OpenGL few times and drawing text is easy using JOGL's extenstions (TextRenderer).
If you choose Swing, than the hard part will be implementation of a 3D transformation. You'd have to write some sort of particle system. The particles would have to reside on a 3D sphere. You personally would be responsible of doing any 3D transformation, but using orthogonal projection that would be trivial. So it's a nice exercise - what You need is here: Wiki's spherical coord sys and here 3d to 2d projection.
After You made all of the transformation only drawing is left. And Java2D and Swing have very convenient API for this. It would boil down to pick font size and draw text at given coordinates. Custom JPanel with overriden paintComponent method would be enough to start and finish.
As for the second choice the hardest part is OpenGL API itself. It's procedural so if You're familiar mostly with Java You would have hard time using non-OO stuff. It can get used to and, to be honest, can be quite rewarding since You can do a lot with it. If you picked OpenGL than you would get all the 3D transformations for free, but still have to transform from spherical coordinate system to cartesian by yourself (first wiki article still helpful). After that it's just a matter of using some text drawing class, such as TextRenderer that comes with JOGL distribution.
So OpenGL helps You with view projection calculations and is hardware accelerated. The Java2D would require more math to use, but in my opinion, this approach seems a bit easier. Oh, and by the way - the Java2D tries to use any graphic acceleration there is (OpenGL or DirectDraw) internally. So You are shielded from certain low-level problems.
For both options You need also to bind mouse coordinates s to rotational speed of sphere. Whether it's Java2D or OpenGL the code will look very similar. Just map mouse coordinates related to the center of panel to some speed vector. At the drawing time You could use the vector to rotate the sphere accordingly.
And one more thing: if You would want to try OpenGL I'd recommend: Processing language created on MIT especially for rich graphic applets. Their 3D API, not so coincidentally, is almost the same as OpenGL, but without much of the cruft. So if You want the quickest prototype that's the best bet. Consult this discussion thread for actual example. Note: Processing is written in Java.
That's not really 3D. There are no perspective transformations or mapping the text on some 3D shape (such as, say, a sphere). What you have is a bunch of strings where each string has an associated depth (or Z order). Strings "closer" to you are painted with a stronger shade of gray and larger font size.
The motion of each string as you move the mouse is indeed a 3D shape which looks like a slanted circle around a fixed center - with the slant depending on where the mouse cursor is. That's simple math - if you figure it for one string, you figure it out for all. And then the last piece would be to scatter the strings so that they don't overlap too much, and give each one the initial weight based on their frequency.
That's what most of the code is doing. So you need to either do the math, or translate the ActionScript to Java2D blindly. And no, there is no need for JOGL.
Why don't you just download the source code, and have a look? Even if you can't write PHP, it should still be possible to read it and figure out how the algorithm works.

Categories

Resources