# sweep a 2D shape into 3D

This topic is 2835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello,
Does anyone know where I can find examples about how to use sweep method to draw objects? I have spent a couple of hours to search online, but I did not find any example code for this. (There are some about sweep-selection, but I do not think this is what I want.) Could anyone give me some simple examples like drawing a cube by translating a square along the line and a cylinder by rotating a line along the circle? I really know the idea, but it is difficult for me to figure out all the details. Hopefully, the example also includes how to map texture to this kind of complicate objects. Any advice is appreciated. Thanks!

##### Share on other sites
A couple of search terms that might help are 'extrusion' and 'procedural mesh'.

(There's actually a tutorial project on the Unity engine site that shows how to do this; although it's Unity-specific, the concepts are general and can be applied elsewhere.)

##### Share on other sites
Yes, I also tried those terms, but only found some advice to implement it. Could you give me some pseudo-code about what I should do step by step?

##### Share on other sites

Yes, I also tried those terms, but only found some advice to implement it. Could you give me some pseudo-code about what I should do step by step?

To be honest, it's a little involved, so even the pseudocode for it would be fairly complex.

If you can specify a single example that you're wondering about though, that might make it easier. (For example, 'I want to sweep a circle along a spline to make a tube'.)

##### Share on other sites
The front:
Convert the 2D polygon into a 3D polygon (by replacing [x,y] with [x,y,0]).
The back:
Clone the 3D polygon and offset it in the Z direction.
The edges:
For each line in the 2D polygon, create a 3D square (by creating 2 copies of the line, one of them offset in the Z direction, and creating two new lines in the Z axis to join them).

##### Share on other sites
As I said, the very simple example is enough like drawing a cube and cylinder by using translation and rotation. Of course, opengl support them as basic 3D objects, but I just want to know how the path defined and if we move 2D shape along the path, how to connect two adjacent shapes?

##### Share on other sites

As I said, the very simple example is enough like drawing a cube and cylinder by using translation and rotation.

Well, that's two examples ;) I was trying to narrow it down to just one to make the question a little easier to answer.

Anyway, Hodgman provided a rough outline for the cube case, so maybe you can use that as a point of departure.

##### Share on other sites
Thanks in advance, and see if I can try it out.

1. 1
2. 2
Rutin
30
3. 3
4. 4
5. 5
khawk
14

• 11
• 11
• 23
• 10
• 9
• ### Forum Statistics

• Total Topics
633647
• Total Posts
3013108
×