java find intersection of a block with a surface in 3D space - java

At the moment we have a bunch of 3d blocks (think cubes) that are imported in a JMonkey 2 canvas.
I need to find an intersection of these blocks with a 3D surface that is imported by the user.
The problem is that I have no idea how to do this in JME or any other 3D engine for that matter.
If anyone has any experience using JMonkey for this kind of taks, or maybe you did it using some other 3D engines could you please provide some code hints, maybe links to relevant resources?
edit for clarification: I need to divide the block into 2 shapes: below/above the surface.
Thanks

It depends on what you want to accomplish, just find out IF it intersects or "where" it intersects. It will be easier (mathematically) if your boxes are AABB (axis aligned bounding boxes), that is - aligned with the xyz axis and not rotated. Is this the case?
However, you have support in JME for these kind of tasks. You might want to read this text: http://jmonkeyengine.org/wiki/doku.php/jme3:advanced:collision_and_intersection

Related

Turn a set of 3d coordinates into polygonal "landscape" in Java

I'm working on a visualization project. From the data I have calculated the X, Y, and Z coordinates for a large set of points. Using Processing it was very simple to draw this out with lines and dots.
From the top it looks like this:
And from a side angle you can see how it occupies 3D space
The part I'm struggling with is turning this into polygons. I need the end result to be something I can export as a .obj file, and then later open in Blender or similar 3D modelling programs.
The two main issues are that these points are not on a grid, but are instead organized in a circle based on radian angles, and that the triangle structure isn't all that simple.
I tried drawing out my own polygons (it's kinda sorta working), but I'm getting to the point where the maths are getting a bit too complex to handle and my code is bloated with arrays, if statements, and for loops...
Surely there must be a better way? Are there any plugins maybe that would help me with this task? Or some techniques I should take a look at?
Processing has screenX() and screenY() functions that take a 3D point and return a 2D point. That sounds like pretty much exactly what you're looking for. Please see the reference for more info.

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.

Using Java & BoofCV to detect shapes in an image file

I've not found anything here or on google. I'm looking for a way to identify shapes (circle, square, triangle and various other shapes) from a image file. Some examples:
You get the general idea. Not sure if BoofCV is the best choice here but it looks like it should be straightforward enough to use, but again I know nothing about it. I've looked at some of the examples and I though before I get in over my head (which is not hard to do some days), I thought I would ask if there is any info out there.
I'm taking a class on Knowledge Based AI solving Ravens Progressive Matrix problems and the final assignment will use strictly visual based images instead of the text files with attributes. We are not being graded on the visual since we only have a few weeks to work on this section of the project and we are encouraged to share this information. SOF has always been my go to source for information and I'm hoping someone out there might have some ideas on where to start with this...
Essentially what I want to do is detect the shapes (?? convert them into 2D geometry) and then make some assumptions about attributes such as size, fill, placement etc, create a text file with these attributes and then using that, send it through my existing code based that I wrote for my other projects to solve the problems.
Any suggestions????
There are a lot of ways you can do it. One way is to find the contour of the shape then fit a polygon to it or a oval. If you git a polygon to it and there are 4 sides with almost equal length then its a square. The contour can be found with binary blobs (my recommendation for the above images) or canny edge.
http://boofcv.org/index.php?title=Example_Fit_Polygon
http://boofcv.org/index.php?title=Example_Fit_Ellipse

java 3D drawing

I have a matrix that includes X-Y-Z coordinates of an environment. I want to render this matrix in a 3D view, coloring the coordinates in terms of depth. For example, the coordinates are taken from a room, so I'd like this 3D view screen as room screen. How can I do that in Java?
If you don't have a specific question related to programming (in Java), I'l lrecommend you go through the Java 3D tutorial from Sun: http://java.sun.com/developer/onlineTraining/java3d/
You could of course wait for someone to serve you this on a silver platter, but if you then need something changed, you can't do it, because you don't understand any of it.
Better start learning yourself.
Good luck!

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