v5.0
Returns the center and extents of a bounding capsule of the Geometry object. If an input transform is specified, it is applied to the Geometry before the bounding capsule is calculated.
Object Geometry.GetBoundingCapsule( siVolumeCenterMethod in_centerMethod, siBoundingCapsuleMethod in_axisMethod, Object in_pXfoObjectToBCapsuleSpace ); |
oArray = Geometry.GetBoundingCapsule( [Type], [Type], [Transform] ); |
1-dimensional Array containing five values: the X, Y and Z coordinates of the center, followed by the length of the central cylinder (excluding the capping hemispheres) and the radius of the capping hemispheres and cylinder.
| Parameter | Type | Description |
|---|---|---|
| Type | siVolumeCenterMethod | The technique used to calculate the center of the bounding
capsule
Default Value: siVolumeCenterMethodBBoxCenter |
| Type | siBoundingCapsuleMethod | The technique used to calculate the axis of the bounding
capsule
Default Value: siBoundingCapsuleMethodBestAxis |
| Transform | SITransformation | Transform to be applied to the Geometry before the bounding capsule is calculated |
/*
Example using no input transform and default parameters
*/
// Create and move (rotate and translate) a torus
NewScene( null, false ) ;
var oTorus = ActiveSceneRoot.AddGeometry( "Torus", "MeshSurface" ) ;
SelectObj( oTorus ) ;
Rotate(null, 45, 0, 0, siAbsolute, siPivot, siObj, siX, null, null, null, null, null, null, null, 0, null) ;
Translate(null, 3, 2, 1, siAbsolute, siPivot, siObj, siX, null, null, null, null, null, null, null, null, null, 0, null) ;
// Find the bounding capsule
var vba = new VBArray( oTorus.ActivePrimitive.Geometry.GetBoundingCapsule() ) ;
var jsa = vba.toArray() ;
// Report the (local) center and radius
Application.LogMessage( "center:" + jsa[0] + ", " + jsa[1] + ", " + jsa[2] ) ;
Application.LogMessage( "length:" + jsa[3] ) ;
Application.LogMessage( "radius:" + jsa[4] ) ;
|
/*
Example using an input transform to preserve scaling and non-default parameters
*/
// Create and move (rotate and translate) a torus
NewScene( null, false ) ;
var oTorus = ActiveSceneRoot.AddGeometry( "Torus", "MeshSurface" ) ;
SelectObj( oTorus ) ;
Scale(null, 0.5, 0.5, 1, siAbsolute, siGlobal, siObj, siY, null, null, null, null, null, null, null, 0, null) ;
oTransform = oTorus.Kinematics.Local.Transform ;
// Find the bounding capsule
var vba = new VBArray( oTorus.ActivePrimitive.Geometry.GetBoundingCapsule( siVolumeCenterMethodCOG, siBoundingCapsuleMethodXAxis, oTransform) ) ;
var jsa = vba.toArray() ;
// Report the (local) center and radius
Application.LogMessage( "center:" + jsa[0] + ", " + jsa[1] + ", " + jsa[2] ) ;
Application.LogMessage( "height:" + jsa[3] ) ;
Application.LogMessage( "radius:" + jsa[4] ) ;
// Build a capsule that shows the bounding volume
var oSphere = ActiveSceneRoot.AddPrimitive("Sphere" ) ;
oSphere.radius = jsa[4] ;
oSphere.PosX = jsa[0] + 0.5*jsa[3];
oSphere.PosY = jsa[1] ;
oSphere.PosZ = jsa[2] ;
var oSphere2 = ActiveSceneRoot.AddPrimitive("Sphere" ) ;
oSphere2.radius = jsa[4] ;
oSphere2.PosX = jsa[0] - 0.5*jsa[3];
oSphere2.PosY = jsa[1] ;
oSphere2.PosZ = jsa[2] ;
var oCylinder = ActiveSceneRoot.AddPrimitive("Cylinder" ) ;
oCylinder.radius = jsa[4] ;
oCylinder.height = jsa[3] ;
oCylinder.PosX = jsa[0] ;
oCylinder.PosY = jsa[1] ;
oCylinder.PosZ = jsa[2] ;
Rotate(oCylinder, 0, 0, 90.0, siAbsolute, siGlobalCOG, siObj, siXYZ, null, null, null, null, null, null, null, 0, null);
// Rotate them to align graphically
var oColl = new ActiveXObject("XSI.Collection") ;
oColl.Add( oCylinder ) ;
oColl.Add( oSphere ) ;
oColl.Add( oSphere2 ) ;
Rotate( oColl , 0, 90.0, 0, siRelative, siGlobalCOG, siObj, siXYZ, null, null, null, null, null, null, null, 0, null);
// Expected results:
//INFO : center:0, -1.734723475976807e-18, 2.0816681711721685e-16
//INFO : height:8
//INFO : radius:4
|