Difficulty:: Medium.
Next Tutorial: Creating a Simple Wheel Part

The Toroid Primitive

Primitives are those geometric objects without mechanical meaning. These objects may be simple, like the cube or more elaborated like the Toroid or the Rounded Box.

With primitive objects OpenScad code is directly inserted in the class, while primitive components are made from primitive objets.

In this example we will show how to create a Toroid primitive. OpenSCAD does not have this primitive. Developers have created modules (which are similar to C++ functions) in order to provide toroids. The advantage of OOML is that once the primitive is created it works as any other component. You can translate, rotate, add, etc. it. And you can of course inherit other objects from it or create more complex parts or primitives using the Toroid (great, isn't it??).

All primitive components must inherit from the AbstractObject Class (AbstractPart inherits from this):

#include <core/AbstractPart.h>
 
class OOMLComponents_EXP_DEC Toroid : public AbstractPart
{
public:
 // ...

For the toroid, apart from the default constructor we have implemented a parametrized one:

	/**
	 * \brief Default constructor.
	 */
	Toroid() :
		Component(),
    _toroidRadius(1.0),
    _sectionRadius(0.5),
    _faces(100)
	{
		 build();
	}
	/**
	 * \brief Default parametrized constructor.
	 *
         * \param toroidRadius Radius of the toroid.
         * \param sectionRadius Radius of toroid's section.
	 * \param faces Number of faces of the rendered toroid.
	 */
	Toroid(double toroidRadius, double sectionRadius, unsigned int faces=100) :
    Component(),
    _toroidRadius(toroidRadius),
    _sectionRadius(sectionRadius),
    _faces(faces)
    {
       if (_sectionRadius > _toroidRadius)
       _sectionRadius = _toroidRadius;
       build();
    }

The build functions is the function in charge of creating the toroid form other OOML primitives.

Component2D circle(Circle(_sectionRadius,_faces).translate(_toroidRadius, 0.0, 0.0));
Component toroid = circle.rotateExtrudedCopy(10, _faces);
 
set(toroid.get());

This last function set(toroid.get()) just sets the current component.

The full implementation can be seen in:

Next Tutorial: Creating a Simple Wheel Part

Recent changes RSS feed Creative Commons License Donate Minima Template by Wikidesign Driven by DokuWiki