Search code examples
c++algorithmopengl3dcurve

Given two sets of xyz coordinates and a value for sag (a) can I draw a catenary between those points in OpenGL?


I am trying to create a non-moving wire in 3d space in C++ OpenGL using a catenary formula. I would like to specify the xyz coordinates of the two fixed points (poles the wire is strung between) and a value for a in the formula to represent the amount of sag the wire has. I'll need to loop through the formula based on a precision count (number of line segments to draw).

In my OpenGL world, x and y are horizontal, and positive y is up, so the wire will always sag in negative y. So if you look straight down along the y axis the wire will appear as a straight line. But the two end points may not be on the same plane horizontally (different y values).

All the examples of a catenary I've seen are 2d...I need to draw it in 3d, which is racking my brain. ;)


Solution

  • What you'd want to do is take a 2D catenary and transform it onto the plane you want. The implementation you described says it "will appear as a straight line" from above. So, this equation fits on a 2-dimentional plane that can be translated along the X & Z axes, and rotated around the Y axis to fit a given orientation.