How to Plot A 3D Ring of any given shape?

Say for example I have a 2D matrix that makes a simple shape like a star, rectangle or circle. How can I take this 2D shape and turn it into a 3D ring? If it was a star, a star shaped ring, if its a square, a square shaped ring and so on...

2 Comments

Would you like to extrude your 2D shape into a 3D shape? And what is the intended result? A plot of this object or just a matrix description?
I would like to first make a 3d matrix of it and then plot it as a point cloud. Yes I would like to extrude a 2D shape into a 3D one.

Sign in to comment.

 Accepted Answer

Create a reference set of vertices centered around 0, 0, and a description of faces joining them. I suggest using something compatible with patch()
Now translate the reference point out to what would correspond to angle 0 in the ring.
Now iterate.
Use makehgtform to create a transform matrix that would describe rotating (relative to the origin) by the appropriate angle for this iteration.
Now apply the transform matrix to the reference vertex coordinates by matrix multiplication, keeping them in the same relative order. Record the rotated coordinates for your point cloud. Usethe rotated coordinates and the previously constructed face information to patch() the rotated object into visual existence.
After all of the iterations, use the recorded vertices to patch() into place faces joining each rotated object to its adjacent rotated object -- the skin of the ring.
If your object being rotated has no internal structure such that the skin is all you care about then you can skip the patch() as you iterate, just using the list of final coordinates to build the skin.

4 Comments

What if you have a matrix of points, can you still do the same process?
If you only have a matrix of points without face information then you will not be able to patch() the individual wireframe steps, but that is not crucial.
After you have all the rotated points, you have the information to connect each point to its rotated successor and predecessor. That is enough information to create lines.
However if you do not have information about how the points in your matrix connect together then you have a challenge of how to make the faces, of knowing what to connect together. You can use boundary() to help but you will find it gives odd triangulations sometimes. This gets to be a particular challenge for more complicated original clouds in which the rotation angle between steps is small, in which case links can accidentally get made between adjacent rotations instead of internally in the matrix.
Could you show me an example of how to do this with a simple matrix like this
xy = [4 0; 8 1; 4 2; 1 9; 3 4];
Not without writing the code for you. The algorithm I set out should be enough for you to create the point cloud of the ring. Once you have done that part then we will look more closely at the challenges of drawing a solid around the point cloud.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!