You just need to close the loop by adding the first vector to the end of vectors again. It would be easier to include all the x value in one vector, y values in another vector and so on. Let's say x=[1 -1 -2], y=[1 1 -2], z=[1 1 -2]. Then, after adding the first vector again, you have x=[1 -1 -2 1], y=[1 1 -2 1], z=[1 1 -2 1] .