Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java2D - morph/interpolate two Shapes

Is there some way - a library or an algorithm - that can be used to interpolate between two instances of java.awt.Shape, or its path iterators? For example, to transition seamlessly between a rectangle and an ellipse? Or the more general case of a Path2D.

like image 387
0__ Avatar asked Jan 31 '26 10:01

0__


1 Answers

  1. There is a class Morphing2D in the SwingX project. My preliminary testing shows, however, that it is restricted to shapes that do not contain SEG_MOVETO elements, and also that it doesn't do any fancy alignment between the two shapes, so the transition is not always ideal.

  2. There is a software ReportMill that contains a Morphing2D. After investigation that company illegally copied the original SwingX code and pasted it into their closed source proprietary product. (An LGPL violation was filed with GNU)

  3. I found an example for JavaFX that seems to support move-to commands. This might have been included in JFX 1.x, but seems not to be part of JFX 2.x. Internally, a translation to and from com.sun.javafx.geom.* is used which seems to be 98% compatible with standard java.awt.geom.*, so an adaptation would be easy.

Edit: My backport from JFX to Java2D works.

like image 172
0__ Avatar answered Feb 03 '26 09:02

0__



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!