Loading...
Logo
Processing Forum
Hi guys, I am a new user of Toxiclibs and not particularly expert of 3D. What would be the simples way to create a prism with Toxiclibs where the 2 poligons at the top and bottom are different? Do I have to calculate all the mesh (triangles) by myself?

Thanks a lot, chr

Replies(5)

Meshes are built face by face, but there are many ways to construct them in Toxiclibs. For starters, Toxiclibs has a few SurfaceMeshBuilders to create meshes using Paul Bourke's SuperEllipsoids and SphericalHarmonics code, but those are perhaps not what you are looking for now. Also, there are many different routes to end up with a mesh and convert between them.

Here, you could write a method that constructs the prism shape based on a few parameters. This will make it more flexible and allow you to write the code once (aka solve it) and then use it with different parameters. What I mean is don't calculate it yourself in the sense that you hard-code coordinates, just write a method that will solve it flexibly for you.

I release the above is a somewhat abstract answer. A more concrete tip would be that you could start with a Polygon2D and then use the toMesh functionality.

Also, what kind of prism do you want when you say the top and bottom polygons are different?

Hey Chris, long time no see :) Just v.briefly... If you merely want the top and bottom to be different sizes, but same shape, you could just create a cone with different radii for north/south cap and sample it at resolution=3 to turn into a TriangleMesh...
Copy code
  1. import toxi.geom.*;
  2. import toxi.geom.mesh.*;

  3. /**
  4.  * order of parameters:
  5.  * origin (object center)
  6.  * direction (normalized)
  7.  * north radius
  8.  * south radius
  9.  * length
  10.  */
  11. Cone cyl=new Cone(new Vec3D(),new Vec3D(0,1,0),50,100,200);

  12. // sample as triangle cross section and produce mesh
  13. TriangleMesh mesh=(TriangleMesh)cyl.toMesh(3);

  14. // save
  15. mesh.saveAsSTL(sketchPath("prism.stl"));
Away teaching this week, so answers might take some time....

Hi guys, the two polygons (north and south cap) will have the same amount of sides. Just different dimension and proportions between the sides. Maybe even a rotation :)

Hi Karsten, yeah quite some time indeed, I guess your kids are already at Uni by now! :)
Not printing out anything yet, but actually it might happen. I wouldn't mind to catch up with you when you have some time!


Soon, chr
I think I did it


I struggle to make it smoother, tried all the subdivisions. Would be also great to hide the points visual debug :)


Thanks, chr
Ok, "the points visual debug" was the face normals :)