• Re: Drawing Archimedes Spiral in PS

    From jdaw1@jdawiseman@gmail.com to comp.lang.postscript on Mon Aug 8 15:24:29 2022
    From Newsgroup: comp.lang.postscript

    This reply might be too late for the original poster; nonetheless might help later readers.
    I needed (well, wanted) an Archimedean spiral, that is, a spiral in which radius is a fixed multiple of angle. It rCyneededrCO to be pixel-precise, but also light, that is, not made of needlessly many pieces.
    Of course it could be done with many small linetorCOs. But that would not be light, and also, just yuck!.
    So, curvetorCOs. Within the PostScript at https://github.com/jdaw1/placemat/blob/main/PostScript/placemat.ps
    is a command ArchimedeanSpiralPath.
    It uses B|-zier cubics that look like a part of a spiral (at most 45-# of it). A B|-zier cubic is specified by eight parameters. Naturally, it must go through the endpoints of the spiral fragment rCo consuming four parameters. At the start and end the slopes must be precisely tangent to the spiral rCo two more parameters. And, the cute extra two conditions: at each end the curvature of the B|-zier must precisely match the curvature of the spiral.
    So ArchimedeanSpiralPath calls ApproximatingCurve, which generates these fragments. Consider plotting a function parameterised as x(a), y(a). ApproximatingCurve takes, for the two end points, the values, single derivatives (wrt a) and double-derivatives, and returns the middle two control points of a curveto satisfying the location-slope-curvature conditions. It is a usefully general-purpose function.
    ApproximatingCurve needs to solve several quartic equations. Solving high-order polynomials should be illegal in PostScript, but luckily isnrCOt, so is done with the function PolynomialRoots, called by ApproximatingCurve.
    All of these are necessary, and also a few small pieces indicated in the comments.
    ArchimedeanSpiralPath chooses close-ish angle separations for the innermost 180-#, including reU2 radians ree 81.028-#, being the point at which curvature is maximal. Beyond 180-# it uses multiples of 45-#, for which the ApproximatingCurve is very very close.
    Share and enjoy.
    --- Synchronet 3.21d-Linux NewsLink 1.2