Spline solid from clips.

 

Let's create a smooth solid from three clips - splines. Two of the splines are identical but moved and turned one about another.

 

This code creates two clips:

 

SG_POINT tmpPnt;

 SG_SPLINE* spl1 = SG_SPLINE::Create();

 int fl=0;

 for (double i=0.0;i<2.0*3.14159265;i+=0.4)

 {

         tmpPnt.x = ((double)(fl%3+2))*cos(i);

         tmpPnt.y = ((double)(fl%3+2))*sin(i);

         tmpPnt.z = 0.0;

         spl1->AddKnot(tmpPnt,fl);

         fl++;

 }

 spl1->Close();

 

 sgCSpline* spl1_obj = sgCreateSpline(*spl1);

 SG_SPLINE::Delete(spl1);

 sgGetScene()->AttachObject(spl1_obj);

 spl1_obj->SetAttribute(SG_OA_COLOR,12);

 spl1_obj->SetAttribute(SG_OA_LINE_THICKNESS, 2);

 

 SG_SPLINE* spl2 = SG_SPLINE::Create();

 

 tmpPnt.x = 0.0; tmpPnt.y = -0.9; tmpPnt.z = 2.0;

 spl2->AddKnot(tmpPnt,0);

 tmpPnt.x = 1.4; tmpPnt.y = 0.9; tmpPnt.z = 2.0;

 spl2->AddKnot(tmpPnt,1);

 tmpPnt.x = -1.6; tmpPnt.y = 0.6; tmpPnt.z = 2.0;

 spl2->AddKnot(tmpPnt,2);

 tmpPnt.x = -1.2; tmpPnt.y = -1.6; tmpPnt.z = 2.0;

 spl2->AddKnot(tmpPnt,3);

 spl2->Close();

 

 sgCSpline* spl2_obj = sgCreateSpline(*spl2);

 SG_SPLINE::Delete(spl2);

 sgGetScene()->AttachObject(spl2_obj);

 spl2_obj->SetAttribute(SG_OA_COLOR,12);

 spl2_obj->SetAttribute(SG_OA_LINE_THICKNESS, 2);

 

 sgGetScene()->AttachObject(spl1_obj);

 sgGetScene()->AttachObject(spl2_obj);

 

The third clip will be the copy of the first one but moved and turned:

 

sgC2DObject* ooo[3];

ooo[1] = spl1_obj;

ooo[0] = spl2_obj;

ooo[2] = (sgC2DObject*)spl2_obj->Clone();

 

sgGetScene()->AttachObject(ooo[2]);

 

SG_POINT axeP = {0.0, 0.0, 0.0};

SG_VECTOR axeD = {0.0, 0.0, 1.0};

axeD.z = 0.0; axeD.x = 1.0;

ooo[2]->InitTempMatrix()->Rotate(axeP,axeD, 3.14159265/4.0);

SG_VECTOR trV = {-1.0, 1.0, -3.0};

ooo[2]->GetTempMatrix()->Translate(trV);

ooo[2]->ApplyTempMatrix();

ooo[2]->DestroyTempMatrix();

 

This code creates the solid itself:

 

 

  double ppp[3];

 ppp[0] = 0.1;

 ppp[1] = 0.0;

 ppp[2] = 0.2;

 

 

 sgCObject* lsf = sgSurfaces::SplineSurfaceFromSections((const sgC2DObject**)(&ooo[0]),

         ppp,3,true);

 

 sgGetScene()->AttachObject(lsf);

 lsf->SetAttribute(SG_OA_COLOR,23);

 

Then let's move the obtained solid:

 

SG_VECTOR transV1 = {8,0,0};

 lsf->InitTempMatrix()->Translate(transV1);

 lsf->ApplyTempMatrix();

 lsf->DestroyTempMatrix();

 

See also:

sgSurcfaces::SplineSurfaceFromSections  

sgCSpline   SG_SPLINE

sgCObject::Clone

sgGetScene sgCScene::AttachObject   sgCObject::SetAttribute

 

Illustration:

splin_bod