• Looking for curve generating functionality

    From Jeff Higgins@21:1/5 to All on Wed Apr 12 00:53:24 2023
    Hi all.
    I am investigating the problem of solving jigsaw puzzles.
    So, to start, I need to generate jigsaw puzzles. I found the
    article "Generating SVG Jigsaw Puzzles" and am currently using
    the given code to generate puzzles and their pieces. The given
    code is written in javascript. The article located at https://dev.inventables.com/2016/02/26/generating-svg-jigsaw-puzzles.html
    and is well written, ad-free, and contains all source code.

    My first instinct was to translate the code to Java, but was
    stopped almost immediately for the lack of a curve generating
    function that is supplied in the javascript library D3.js used
    in the article, but not in java.awt.geom. The author describes
    this curve as a "B-spline, with control point duplication on the ends".
    The article contains a nice interactive demo of the curve.

    So my workflow at present is generate the puzzle pieces using
    the given javascript, output SVG, use the Java Batik library
    to convert the SVG to java.awt.geom.Path2d objects. Messy.

    The paths produced by this contain five CubicCurve2d segments
    and determining the needed parameters is considerably more complex.
    I haven't been able to easily and reliably duplicate the
    functionality in Java.

    My math skills are not up to the task of understanding splines
    so searching the web produces mostly content that I am not able
    to consume. Adding Java to the search terms hasn't been much help.

    I am hoping that someone will take the interest to glance at the
    article and be able to some suggest some available Java functionality
    to replace the D3.js functionality.

    Thanks much in advance.
    Jeff Higgins

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jeff Higgins@21:1/5 to Jeff Higgins on Wed Apr 12 04:06:44 2023
    On Wed, 12 Apr 2023 00:53:24 -0000 (UTC), Jeff Higgins wrote:

    Hi all.

    Actually the code that generates the curve is not shown in the article.

    var d3CurvedLine = d3_shape.line().curve(d3_shape.curveBasis);

    var piecePathData = function(piece) {
    return piece.map(function(edge) {
    return d3CurvedLine(edge);
    }).join(" ");
    };

    When I look at the D3 documentation:
    https://github.com/d3/d3-shape#curves

    I see that d3.curveBasis
    "Produces a cubic basis spline using the specified control points.
    The first and last points are triplicated such that the spline starts
    at the first point and ends at the last point, and is tangent to the
    line between the first and second points, and to the line between
    the penultimate and last points."

    And using the nugget of info here: https://stackoverflow.com/a/26707244/17085543

    I believe that what I have is a cubic basis spline of degree 2
    with six knots and four control points. Which is Greek to me.

    But - allowed me to find TinySpline:
    https://github.com/msteinbeck/tinyspline
    Which promises Java bindings.
    And may provide what I'm looking for ... I'll see.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?Arne_Vajh=c3=b8j?=@21:1/5 to Jeff Higgins on Sun Apr 16 20:00:44 2023
    On 4/12/2023 12:06 AM, Jeff Higgins wrote:
    On Wed, 12 Apr 2023 00:53:24 -0000 (UTC), Jeff Higgins wrote:
    Actually the code that generates the curve is not shown in the article.

    var d3CurvedLine = d3_shape.line().curve(d3_shape.curveBasis);

    var piecePathData = function(piece) {
    return piece.map(function(edge) {
    return d3CurvedLine(edge);
    }).join(" ");
    };

    When I look at the D3 documentation:
    https://github.com/d3/d3-shape#curves

    I see that d3.curveBasis
    "Produces a cubic basis spline using the specified control points.
    The first and last points are triplicated such that the spline starts
    at the first point and ends at the last point, and is tangent to the
    line between the first and second points, and to the line between
    the penultimate and last points."

    And using the nugget of info here: https://stackoverflow.com/a/26707244/17085543

    I believe that what I have is a cubic basis spline of degree 2
    with six knots and four control points. Which is Greek to me.

    But - allowed me to find TinySpline:
    https://github.com/msteinbeck/tinyspline
    Which promises Java bindings.
    And may provide what I'm looking for ... I'll see.

    Google also found:

    https://commons.apache.org/proper/commons-math/javadocs/api-3.6.1/org/apache/commons/math3/analysis/interpolation/SplineInterpolator.html

    Arne

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)