f_catenary() Calculate and return catenary related values. The aim is to provide general functionality around which one might build hanging chains or whatever. The general herein approach works by halves with the lowest (or highest) point not offset from the x axis, but rather sitting on it with the curve scaled by the typical 'a' constant to otherwise end on the second passed coordinate. Full curves to be constructed symmetrically with abs(x) or asymmetrically, by multiple pieces. Where using abs(x) for x, it's best to define the x1,y1 - x2,y2 coordinates where x1 is zero and all coordinates are already in the +x,+y coordinate plane. While the code internally normalizes to a working +x,+y space and de-normalizes results, it cannot maintain continuity across zero with respect to results. To use, first solve for 'a' with mode 0. After which use that 'a' constant when calling the f_catenary() with any functional mode > 0. Reference: https://en.wikipedia.org/wiki/Catenary Note. The function's internal solver will numerically fail to find the necessary set up constant 'a', if the ratio of the width to the length the rectangle formed by (x1,y1), (x2,y2) is too small. As a rule, keep it larger than 1/1000. Inputs: 1) x1 - The first, lowest x value at the start of the curve. 2) y1 - The y value at x1. 3) x2 - The second, highest x value at the end of the curve. 4) y2 - The y value at x1. 5) The mode of operation. 0 - Calculate and return the 'a' constant for the passed bounding range. Expensive to calculate. It should be run once prior using the f_catenary() function generally. Inputs (6 and 7) are ignored. 1 - Calculate and return the x value for the given [0..1] 't' value passed as input (7). The calculation is likely too slow for other than parse time use. 2 - Calculate and return the y value for the given [0..1] 't' value passed as input (7). The calculation is likely too slow for other than parse time use. 3 - Vertical y value at x(7) between x1 and x2. 4 - The first derivative, y', at x(7). 5 - The second derivative, y'', at x(7). 6 - The path / arc length at x(7) from x1. If x==x2, this returns the total path length. 7 - Return the 't' value at x(7). (arc len / total path len) 8 - The radius of curvature at x(7). 9 - Slope at x(7). 10 - The angle of the tangent at x(7) relative to the x axis. This can be negative if the y1,y2 values decrease over the range. Return value in radians. 6) a - Constant pre-calculated once by this function. Ignored, if calculating the value itself. This is herein effectively a scaling factor the fundamental catenary curve. 7) x or t - If the input is x, this is a value between >=x1 and <=x2 and inputs are clamped to this range. If the input is a 't' value representing the arc length along the total path length, this is a value in the [0..1] range. // SPDX-License-Identifier: CC-BY-SA-4.0