how to draw a 3D spring?

Hi,

Is there a way to easily draw a 3D spring in OpenGL? It doesn’t have to be fancy. The spine (central line) is always straight. I know VRML has tools to draw springs, donuts, etc. Your help is much appreciated.

Tony

I am not sure what you call springs, but if you need some pre-defined objects like torus (donut ) or the old good teapot, try to use GLUT. It has some predefined Objects you can call without creating it from ground up.

cu
Tom

One way would be to use a 3D model editor to model the spring how you want. There are many free modelers out there so take your pick. Or you could generate a spring using math. You could do something like this: http://mathworld.wolfram.com/Slinky.html and once your curve is generated to your specs, the next step is to tessellate it.

-SirKnight

A spring is a generalised cylinder with a circle cross-section and a ‘springy’ axis.

Conceptually, then:

  • you need to know how to generate points around the circumfrence of the circle. This is easy, right?
  • you need to know how to generate the spring axis. This is easy, also, since you can parameterise a point along the springs axis by some variable, t, and then find its 3D location by some function of t rotated about the circle offset by some function of t representative of how compressed the spring is. An example, but by no means only, function could be the point f(t)=<cos(kt), sin(kt), ct>, where k and c are constants defining how often the spring wraps around and how compressed the spring is for some domain of t. This generates the generalised cylinder axis spiralling down the z axis. The derivative of this function becomes f’(t)=<sin(kt), -cos(kt), c>, which is needed to…
  • loft the crosssection from step 1 into the plane defined by step 2. You can do this because for some point t you know its 3D position in space (the ‘origin’) of the plane and its normal (taken from the derivative). This defines a mapping from your crosssection coordinate system to the 3D coordinate system for that point t, so you can map the cross section points into space.
  • with the set of cross section points in space, you’ll need to connect them up. BUt this is straightforward because you have inbuilt correspondence when you loft your points.

and that’s it. the hardest part is lofting 2D points into 3D, I guess.

OpenGL is not a scene graph.

OpenGL is not a model library.

OpenGL is a high-level abstraction for the specific capabilities of 3D rendering hardware. Nothing more; nothing less.

Think of OpenGL as a device driver.

Why can’t you just get the math to draw a torus, then modify the equation to vary the height, which should expand it into something that looks like a spring?