A ray tracing algorithm for an arbitrarily shaped axially symmetric graded index waveguide was proposed. This was achieved by considering the center of the waveguide (optical axis) as a set of discrete points. The refractive index depends on the distance of the ray position from the optical axis. This distance was approximated as the shortest distance between the ray position and a point in the set. Using this algorithm, ray tracing could be performed, regardless of the waveguide configuration. In this study, a precise explanation of the algorithm is given and the errors are evaluated. A technique to reduce computing time is also included.