From 13951475e9a63d37188471f2656c995efc5450dd Mon Sep 17 00:00:00 2001 From: cignoni Date: Thu, 11 Feb 2016 15:47:06 +0000 Subject: [PATCH] Added SuperEllipsoid and SuperToroid functions Thanks to Antonio Nicoletti --- vcg/complex/algorithms/create/platonic.h | 81 ++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/vcg/complex/algorithms/create/platonic.h b/vcg/complex/algorithms/create/platonic.h index 6fc640a5..d2351f13 100644 --- a/vcg/complex/algorithms/create/platonic.h +++ b/vcg/complex/algorithms/create/platonic.h @@ -600,7 +600,88 @@ void Torus(MeshType &m, float hRingRadius, float vRingRadius, int hRingDiv=24, i } +/** + * SuperToroid + * + * Generate a a supertoroid, e.g. a member of a family of doughnut-like surfaces + * (technically, a topological torus) whose shape is defined by mathematical formulas + * similar to those that define the superquadrics. + */ +template +void SuperToroid(MeshType &m, float hRingRadius, float vRingRadius, float s, float t, int hRingDiv=24, int vRingDiv=12 ) +{ + typedef typename MeshType::CoordType CoordType; + typedef typename MeshType::ScalarType ScalarType; + m.Clear(); + ScalarType angleStepV = (2.0f*M_PI)/vRingDiv; + ScalarType angleStepH = (2.0f*M_PI)/hRingDiv; + auto fnC=[](float a, float b){ + return math::Sgn(cos(a))*pow(abs(cos(a)),b); + }; + auto fnS=[](float a, float b){ + return math::Sgn(sin(a))*pow(abs(sin(a)),b); + }; + float u; + float v; + Allocator::AddVertices(m,(vRingDiv+1)*(hRingDiv+1)); + for(int i=0;i::RemoveDuplicateVertex(m); + tri::Allocator::CompactEveryVector(m); +} +/** + * Generate a SuperEllipsoid eg a solid whose horizontal sections are super-ellipses (Lamé curves) + * with the same exponent r, and whose vertical sections through the center are super-ellipses with + * the same exponent t. + */ +template +void SuperEllipsoid(MeshType &m, float r, float s, float t, int hRingDiv=24, int vRingDiv=12 ) +{ + typedef typename MeshType::CoordType CoordType; + typedef typename MeshType::ScalarType ScalarType; + m.Clear(); + ScalarType angleStepV = (2.0f*M_PI)/vRingDiv; + ScalarType angleStepH = (2.0f*M_PI)/hRingDiv; + auto fnC=[](float a, float b){ + return math::Sgn(cos(a))*pow(abs(cos(a)),b); + }; + auto fnS=[](float a, float b){ + return math::Sgn(sin(a))*pow(abs(sin(a)),b); + }; + float u; + float v; + Allocator::AddVertices(m,(vRingDiv+1)*(hRingDiv+1)); + for(int i=0;i::RemoveDuplicateVertex(m); + tri::Allocator::CompactEveryVector(m); + +} // this function build a mesh starting from a vector of generic coords (objects having a triple of float at their beginning) // and a vector of faces (objects having a triple of ints at theri beginning). template