Instance References with Non-Uniform Scales

This guide discusses non-uniform scaling issues when using the openNURBS toolkit

Problem

In Rhino, you can insert an instance of a block and give it a non-uniform scale (transformation). But, when you read the model, using the openNURBS toolkit, and try to explode the block into its geometric form, the geometry is no longer non-uniformly scaled.

Solution

Not all ON_Geometry-derived classes can be accurately modified with transformations like projections, shears, and non-uniform scaling. For example, if you were to apply a non-uniform scale to a circle, which is represented by an ON_ArcCurve curve, the resulting geometry is no longer a circle.

When exploding an instance reference into its geometric form, first test to see if the instance reference’s transformation is a similarity transformation. This can be done by using ON_XForm::IsSimilarity(). See opennurbs_xform.h for more information.

If the transformation is not a similarity, then convert the geometry into a form that can be accurately modified. This can be done by using the ON_Geometry::MakeDeformable() override on the geometric object…

if (bNeedXform)
{
 // If not a similarity transformation, make sure geometry
 // can be deformed. Generally, this involves convert non-NURBS
 // geometry into NURBS geometry.
 if (0 == xform.IsSimilarity() )
   geometry->MakeDeformable();

 // Do the transformation
 geometry->Transform(xform);
}