Calculating Volume and Surface Area
OCCT provides built-in functions to calculate geometric properties of solid shapes, including volume and surface area. This tutorial demonstrates how to:
- Create a parametric cone solid
- Calculate the volume of the solid using
getSolidVolume - Calculate the surface area using
getSolidSurfaceArea - Format and display the results with proper units
- Use pin labels for visual annotation
The example shows a practical workflow for measuring and displaying geometric properties, which is essential for engineering calculations, material estimates, and design validation.

- Rete
- Blockly
- TypeScript
Script Source (typescript)
// Import required DTOs and types
const { ConeDto, PinWithLabelDto } = Bit.Inputs.OCCT;
type Point3 = Bit.Inputs.Base.Point3;
type Vector3 = Bit.Inputs.Base.Vector3;
// Get access to OCCT modules
const { solid } = bitbybit.occt.shapes;
const { dimensions } = bitbybit.occt;
const { math, text } = bitbybit;
// Demonstrate volume and surface area calculation
// Parametric height value
const height = 5;
// Create a cone
const coneOptions = new ConeDto();
coneOptions.radius1 = 2;
coneOptions.radius2 = 1;
coneOptions.height = height;
coneOptions.angle = 360;
coneOptions.center = [0, 0, 0] as Point3;
coneOptions.direction = [0, 1, 0] as Vector3;
const cone = await solid.createCone(coneOptions);
// Get volume and surface area
const volume = await solid.getSolidVolume({ shape: cone });
const surfaceArea = await solid.getSolidSurfaceArea({ shape: cone });
// Round to 2 decimal places
const roundedVolume = math.roundToDecimals({ number: volume, decimalPlaces: 2 });
const roundedSurfaceArea = math.roundToDecimals({ number: surfaceArea, decimalPlaces: 2 });
// Format as text with units
const volumeText = text.format({
text: "Volume {0} m3",
values: [text.toString({ item: roundedVolume })]
});
const areaText = text.format({
text: "Area {0} m2",
values: [text.toString({ item: roundedSurfaceArea })]
});
// Create pin labels to display the measurements
const volumePinOptions = new PinWithLabelDto();
volumePinOptions.startPoint = [0, height, 0] as Point3;
volumePinOptions.endPoint = [1, height + 3, 0] as Point3;
volumePinOptions.direction = [1, 0, 0] as Vector3;
volumePinOptions.offsetFromStart = 0;
volumePinOptions.label = volumeText;
volumePinOptions.labelOffset = 0.3;
volumePinOptions.labelSize = 0.3;
const volumePin = await dimensions.pinWithLabel(volumePinOptions);
const areaPinOptions = new PinWithLabelDto();
areaPinOptions.startPoint = [0, height, 0] as Point3;
areaPinOptions.endPoint = [1, height + 4, 0] as Point3;
areaPinOptions.direction = [1, 0, 0] as Vector3;
areaPinOptions.offsetFromStart = 0;
areaPinOptions.label = areaText;
areaPinOptions.labelOffset = 0.3;
areaPinOptions.labelSize = 0.3;
const areaPin = await dimensions.pinWithLabel(areaPinOptions);
// Draw the cone and labels
bitbybit.draw.drawAnyAsync({ entity: cone });
bitbybit.draw.drawAnyAsync({ entity: volumePin });
bitbybit.draw.drawAnyAsync({ entity: areaPin });
