# Calculating center line of curved pipe

I want to have have a disk move vertically through a curved pipe. The pipe’s shape and size will stay the same, but the position and rotation in a 3d space will be random.
Is it possible to calculate the centerline of this pipe piece to act as a path for the disk? Is there some function that given the pipe’s position and rotation, and the disk’s current position and rotation, it will tell me where the disk should move to in the next frame?

Here are some instances of the pipes orientation in a 3d space:

Here are the measurements of the curved pipe and the circles that define it:
The pipe is a 30 degree turn.

I assume you are going to be building a curvy pipe out of these pipe segments. All you need is a few local points that define the centerline relative to the mesh. You may get away with just two points, one at the bottom opening and one at the middle (likely the pivot). Once the pipe is constructed, you cycle through each pipe segment and convert the local points into world points using Transform.TransformPoint() to create a set of waypoints. The disk would then walk along the waypoint path. If you need a smoother path then your defined points, you could convert the array of points into a spline. Code to do this conversion has been posted to UA, and third-party tools like iTween (free) can do the job also.

As for defining the local points, you could just use a few empty game objects, or simply hard code them in a script. Note these points will be the centerline when the pipe has rotation of (0,0,0). From your drawing and the knowledge of the pivot point relative to the unrotated mesh segment, you should be able to calculate the points with a calculator and a bit of trig.