|
Gin
|
Calculates the curve of a hanging cable (catenary). More...
#include <gin_catenary.h>
Public Member Functions | |
| Catenary (float x0, float y0, float x1, float y1, float addLength, int numIterations=1) | |
| Creates a catenary curve between two points. | |
| void | calculate (float x0, float y0, float x1, float y1, float addLength, int numIterations=1) |
| Calculates or recalculates the catenary curve between two points. | |
| float | calcY (float x) const |
| Calculates the y coordinate for a given x position on the catenary curve. | |
| std::pair< float, float > | getVertex () const |
| Returns the vertex (lowest point) of the catenary curve. | |
Calculates the curve of a hanging cable (catenary).
A catenary is the natural curve formed by a cable, rope, or chain hanging between two points under its own weight. This class calculates the mathematical catenary curve and provides methods to query points along it.
Common uses:
The curve is defined by two endpoints and the additional length of cable beyond the straight-line distance between the points.
| Catenary::Catenary | ( | float | x0, |
| float | y0, | ||
| float | x1, | ||
| float | y1, | ||
| float | addLength, | ||
| int | numIterations = 1 |
||
| ) |
Creates a catenary curve between two points.
| x0 | X coordinate of the first endpoint |
| y0 | Y coordinate of the first endpoint |
| x1 | X coordinate of the second endpoint |
| y1 | Y coordinate of the second endpoint |
| addLength | Additional cable length beyond the straight-line distance |
| numIterations | Number of Newton-Raphson iterations for precision (default: 1) |
References calculate().
| void Catenary::calculate | ( | float | x0, |
| float | y0, | ||
| float | x1, | ||
| float | y1, | ||
| float | addLength, | ||
| int | numIterations = 1 |
||
| ) |
Calculates or recalculates the catenary curve between two points.
The addLength parameter determines how much "slack" the cable has. A value of 0 would be a straight line (impossible for a real cable). Larger values create more pronounced sag.
| x0 | X coordinate of the first endpoint |
| y0 | Y coordinate of the first endpoint |
| x1 | X coordinate of the second endpoint |
| y1 | Y coordinate of the second endpoint |
| addLength | Additional cable length beyond the straight-line distance (must be > 0) |
| numIterations | Number of Newton-Raphson iterations for precision (default: 1) |
Referenced by Catenary().
Calculates the y coordinate for a given x position on the catenary curve.
Use this to sample points along the curve for drawing.
| x | The x coordinate |
Returns the vertex (lowest point) of the catenary curve.