Moving/translating a set of points on a spline.

Started by
2 comments, last by haegarr 13 years, 9 months ago
If I have a spline that is defined as follows:

        private List<Vector3> controlPoints;            // List of control points for the spline         private ushort[] indices;        private List<Vector3> interpolatedPoints;       // List of interpolated points located on the spline


how should I translate those points should I want the spline to move?

Should I move all the points once each time the spline is moved:

        public void Translate(Vector3 movementVector)        {            for (int i = 0; i < interpolatedPoints.Count; ++i)            {                interpolatedPoints += movementVector;                if (i < controlPoints.Count)                {                    controlPoints += movementVector;                }            }        }


Or should I use a transformation matrix?

Which one would you be inclined to use, and why?
Advertisement
If you only want to do a translation, then do it this way. There's no point in using a matrix (which will use many more operations), when a simpler way will work just as well.
Indeed. I was also avoiding the transformation matrix as I would need to store a collection of transformed points if I were to go with this method.

This is because I will require the world space coordinates of each point for calculations and there would be no point transforming each point each time a specific point is required.

Unless someone has a better suggestion?
It depends on how interpolatedPoints is related to the spline. Transforming both at once means that both a coupled tightly. I assume that interpolatedPoints are used for rendering, so that the graphical representation and the mathematical basis are coupled here!?

However, this part of the code
            for (int i = 0; i < interpolatedPoints.Count; ++i)            {                interpolatedPoints += movementVector;                if (i < controlPoints.Count)                {                    controlPoints += movementVector;                }            }
seems me inefficient and error-prone. It is inefficient because there is a chance that the continous program flow will be disrupted unneccessarily, and there is the chance that too little controlPoints get updated (although some unshown constraints may prevent that). It seems me better to use
            for (int i = 0; i < interpolatedPoints.Count; ++i)            {                interpolatedPoints += movementVector;            }            for (int i = 0; i < controlPoints.Count; ++i)            {                controlPoints += movementVector;            }
instead.

This topic is closed to new replies.

Advertisement