JavaSCAD - primitives

A few words about the primitive 3D types and their methods

In JavaSCAD only the primitive types generate any visible object. Everything you want to see should be a primitive type - however it cutted, scaled or translated any other way. All primitive types are descendant of the abstract Atomic3dModel class which is descendant of the Abstract3dModel abstract class which is the base of every 3D object in JavaSCAD.

Every property of all primitives should be passed through constructor, so there are no setters for those.

There are six primitive types in JavaSCAD: cube, cylinder, prism, sphere, polyhedron, and ring. We will talk about the polyhedron and the ring later, so let's look what the other four do.

Cube

Represents a cube or cuboid centered on the zero coordinate. It has two constructors. With a numeric value it will represent a cube. With a Dims3d object it will represent a cuboid. The dimensions is defined by the x, y, and z values of the Dims3d object.

  // creates a new cube with all dimensions set to 50
  new Cube(50);
  // creates a new cube with 10, 20, and 30 as the x, y, and z dimensions respectively
  new Cube(new Dim3d(10, 20, 30));

Sphere

Represents a sphere centered on the zero coordinate. Not surprisingly its only parameter is the radius of the sphere. The granulity of the sphere is controlled by the values given to the Consts. Please be aware that if you didn't create a Consts object yourself and use the SaveScadFiles class it creates one for you with the default constructor of Consts.

  // creates a new sphere with a radius of 50
  new Sphere(50);

Cylinder

Represents a cylinder or a cone centered on the zero coordinate. There are two ways instantiating a cylinder. With a radius and a length it will be a cylinder. With two radiuses and a length it will be a cone. If the two radiuses given for the cone is equal the new object will represent a cylinder and no error is thrown. Both the bottom and the top radius can be zero for a real cone.

The granulity of the object is managed the same way as for the sphere - please read the information written there.

  // creates a new cylinder with length of 40 and radius of 10
  new Cylinder(40, 10)
  // creates a new cone with a length of 40, bottom radius of 10 and top radius of 5
  new Cylinder(40, 10, 5)

Prism

Represents a prism or a pyramid. These are special cylinder or cone, where the base is not a circle, but a regular polygon. Because of this relation the Prism class is descandant of the Cylinder class in JavaSCAD and has two constructor just like Cylinder has. The only difference is that you need to give the number of sides for the prism or pyramid when instantiating this class.

  // creates a new prism with length of 40, radius of 10 and 6 sides
  new Prism(40, 10, 6)
  // creates a new pyramid with a length of 40, bottom radius of 10, top radius of 5 and 8 sides
  new Prism(40, 10, 5, 8)

On sale