locationtech / jts

The JTS Topology Suite is a Java library for creating and manipulating vector geometry.
Other
1.94k stars 442 forks source link

Single-side offset provides triangular spikes near sharp turns #1006

Open nubblesite opened 10 months ago

nubblesite commented 10 months ago

I'm imagining that this issue is not uncommon. Wondering what sort of settings I need to be using to rid myself of these ugly triangles. Low mitre limit doesn't help, and I think I've tried all possible combos of endCapStyle and joinStyle. Any ideas? image

private fun offsetPolyline(originalPolyline: ArrayList<Point3D>, offsetDistance: Double, closed: Boolean): ArrayList<Point3D> {
        val geometryFactory = GeometryFactory()

        // Step 1: Convert the ArrayList of Point3D into a Coordinate array for JTS
        val coordinates = originalPolyline.map { Coordinate(it.x, it.y) }.toTypedArray()

        // Step 2: Use JTS OffsetCurveBuilder to offset the Coordinate array
        val bufferParameters = BufferParameters(18)
        bufferParameters.joinStyle = JOIN_MITRE
        bufferParameters.endCapStyle = CAP_FLAT
        bufferParameters.mitreLimit = 1.0
        val curveBuilder = OffsetCurveBuilder(geometryFactory.precisionModel, bufferParameters)
        val offsetCoordinates = curveBuilder.getOffsetCurve(coordinates, offsetDistance)

        // Step 3: Convert the resulting Coordinate array back to ArrayList<Point3D>
        val offsetPolyline = ArrayList<Point3D>()
        for (coordinate in offsetCoordinates) {
            offsetPolyline.add(Point3D(coordinate.x, coordinate.y, 0.0, 0.0))
        }

        return offsetPolyline
    }
Inamm7753a commented 10 months ago

[ ]

@``__