Simplest way to get a polygon from Illustrator to Java? - java

What's the simplest way to get a polygon (doesn't need curves etc, just an array of points) from Illustrator (or any other vector graphics program, for that matter) into a Java Polygon object?
I'm not really eager to implement a very heavy SVG class, my app needs to be as light-weight as possible.
I know it's a very wide question, but so may your answers be. Thanks in advance, guys.

You might want to try "FXG Converter (webstart)" (http://idisk.mac.com/han.solo-Public/fxgconverter.jnlp) from http://harmoniccode.blogspot.com/.

Related

How to draw efficiently arrows on a canvas with JavaFX 8?

I am looking for a very simple and efficient way to draw arrows in JavaFX 8, what is the best way to achieve that (performance-wise if let's say I'm willing to draw hundreds or thousands of them)?
I've heard using a Canvas to draw on it is quite efficient.
However, I do not know whether the best implementation is to go with:
Inheriting from the class Shape [https://docs.oracle.com/javase/8/javafx/api/javafx/scene/shape/Shape.html]
Inheriting from the class Line? [https://docs.oracle.com/javase/8/javafx/api/javafx/scene/shape/Line.html]
Bothering myself every now and then with the GraphicContext class in order to create the arrow manually? Does not sound like the good idea.
Other strategy?
The best method depends on various factors which we don't know so it's difficult to give a clear answer here. I will try to give a few general hints though and you will have to decide yourself if these are applicable to your problem.
For mass drawings using the canvas sounds like a good idea.
Simple lines and rectangles are much faster than paths (also polylines and polygons).
Some line joins/caps are faster than others.
Avoid transparency.
It may be helpfull to consider specialized approaches like, e.g. creating images of your arrows and then just painting these images.
Michael

Vector graphics implementations in java [duplicate]

This question already has answers here:
Visualize vector graphics in Java, which library?
(2 answers)
Closed 8 years ago.
I am currently trying to make a game using java, and I wanted to use vector graphics to avoid the blocky feel of many other current games. I've looked into using some of the various Shape implementations in java like Path2D and Area. The problem is is that neither one has all the functionality I need. Here is what I am looking for:
I need to be able to create it using vector graphics based methods (lineTo(), moveTo(), etc.)
I need to be able to draw it onto a JPanel
I need to be able to test whether two instances intersect, or at the very least, whether one contains a point.
Finally, I need to be able to merge them together or subtract one from another.
I know this is kind of a long shot, but I was hoping someone might know of a library or something that has this functionality.
As far as libraries go, I don't have an answer.
I might have missed a point, but as far as I know, Graphics2D Shapes and areas have all the functions you listed. What do they lack you need ?
Of course, JavaFx has all you asked for, but if you want to write a Swing app:
I did not use them for a game, but for an editor, and here is what I would suggest:
create your own graphic element class. Use Shapes and area to implement them, and make them Composite elements.
for collision, have a getArea() method on your elements. The area can be the union of all areas. that represent your element.
in real life, it might be a bit slow, however... Consider doing some pre-rendering as bitmap pictures (maybe when starting the game, when you know the resolution ?)

How to create and rotate tridimensional matrix in Java or AS3

i'm currently working on a personal project and i need to save short ints in a tridimensional array (cube) that allows me to "rotate" the cube and change its orientation (of course i just mean the values inside the matrix). Also i would need to make displacements (translations) of all the values towards one of the axis. Is there a premade way to do this? If it's a java or as3 solution approach it would be nice since i feel more comfortable on one of those technologies.
Thank you in advance for your time!
There is a Vector3D and Matrix3D classes in AS3. Use what you need :)

Java graphics library with methods to capture mouse evens on drawn objects

I am looking for a java library that can draw lines and shapes (2d) as well as be able to capture the mouse events on the drawn objects. I will also need the ability to zoom and out on the drawn objects.
I might be asking for a lot but anything close will save me some time re-inventing the wheel.
P.S. It will be even better if the library renders the shapes as objects.
Thanking you all in anticipation.
Cheers
Simple answer will be:
LWJGL .
There you have an access to OpenGL, OpenCL, and OpenAL libraries.

Creating a composite Shape in Java 2D

Using Java 2D I've patched several Bezier curves (CubicCurve2D) together to create a "blob". The problem I now face is how to:
Efficiently fill the blob with a given colour.
Efficiently determine whether a given point lies inside the blob.
I noticed thst CubicCurve2D implements Shape which provides numerous contains methods for determining "insideness" and that Graphics2D is able to fill a Shape via the fill(Shape) (which I believe uses Shape's getPathIterator methods to do this).
Given this I was hoping I could create a composite Shape, whereby my getPathIterator(AffineTransform) method would simply link the underlying PathIterators together. However, this is producing a NoSuchElementException once my shape contains more than one CubicCurve2D. Even if I do manage to achieve this I'm not convinced it will work as expected because a CubicCurve2D is always filled on the convex side, and my "blob" is composed of concave and convex curves. The "contains" problem is even harder as a point can legitimately lie within the blob but not within any of the individual curves.
Am I approaching this problem in the correct way (trying to implement Shape?) or is there an idiomatic way to do this that I'm unaware of? I would have thought that the problem of compositing geometric shapes would be fairly common.
Does anyone have any suggestions regarding how to solve this problem?
Thanks in advance.
I'm not sure I understand your question but composite shapes can be created with the class java/awt/geom/Area.
Looking to Shape for a solution is the right way to go about this. If you have a collection of curves that you are trying to assemble into a shape, I would suggest that you use a GeneralPath. Simply add your curves, or straight line segments, as required. Look to the interface to see the various append methods. Also note that you can 'complete' the shape by joining the last point to the starting point.
Once the path is closed, there are a number of different versions of contains() that can be used, please take the time to read each of their descriptions, as there are trade-offs in terms of speed and accuracy, depends on your application.
Also it is easy to get a shape from the path, and fill it, transform it, etc.

Categories