Coons surface by four boundary contours.

 

Let's create a Coons surface by four boundary contours - four splines.

The necessary requirment when creating the Coons surface is matching the end points of boundary contours.

 

This code creates the first spline:

SG_POINT tmpPnt;

 

 SG_SPLINE* spl1 = SG_SPLINE::Create();

 

 tmpPnt.x = -6.0; tmpPnt.y = 0.0; tmpPnt.z = -1.0;

 spl1->AddKnot(tmpPnt,0);

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

 spl1->AddKnot(tmpPnt,1);

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

 spl1->AddKnot(tmpPnt,2);

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

 spl1->AddKnot(tmpPnt,3);

 tmpPnt.x = -1.0; tmpPnt.y = 0.0; tmpPnt.z = 1.0;

 spl1->AddKnot(tmpPnt,4);

 tmpPnt.x =2.0; tmpPnt.y = 0.0; tmpPnt.z = 1.0;

 spl1->AddKnot(tmpPnt,5);

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

 spl1->AddKnot(tmpPnt,6);

 tmpPnt.x =4.0; tmpPnt.y = 0.0; tmpPnt.z = 1.0;

 spl1->AddKnot(tmpPnt,7);

 

 sgCSpline* spl1_obj = sgCreateSpline(*spl1);

 SG_SPLINE::Delete(spl1);

 sgGetScene()->AttachObject(spl1_obj);

 spl1_obj->SetAttribute(SG_OA_COLOR,0);

 spl1_obj->SetAttribute(SG_OA_LINE_THICKNESS, 1);

 

This code creates the second spline:

SG_SPLINE* spl2 = SG_SPLINE::Create();

 

 tmpPnt.x = -5.0; tmpPnt.y = 4.0; tmpPnt.z = 2.0;

 spl2->AddKnot(tmpPnt,0);

 tmpPnt.x = -3.0; tmpPnt.y = 4.0; tmpPnt.z = 1.0;

 spl2->AddKnot(tmpPnt,1);

 tmpPnt.x = -2.0; tmpPnt.y = 4.0; tmpPnt.z = 2.0;

 spl2->AddKnot(tmpPnt,2);

 tmpPnt.x = -1.0; tmpPnt.y = 4.0; tmpPnt.z = -1.0;

 spl2->AddKnot(tmpPnt,3);

 tmpPnt.x =4.0; tmpPnt.y = 4.0; tmpPnt.z = 0.0;

 spl2->AddKnot(tmpPnt,4);

         

 sgCSpline* spl2_obj = sgCreateSpline(*spl2);

 SG_SPLINE::Delete(spl2);

 sgGetScene()->AttachObject(spl2_obj);

 spl2_obj->SetAttribute(SG_OA_COLOR,10);

 spl2_obj->SetAttribute(SG_OA_LINE_THICKNESS, 2);

 

This code creates the third spline:

SG_SPLINE* spl3 = SG_SPLINE::Create();

 

 tmpPnt.x = -6.0; tmpPnt.y = 0.0; tmpPnt.z = -1.0;

 spl3->AddKnot(tmpPnt,0);

 tmpPnt.x = -7.0; tmpPnt.y = 0.5; tmpPnt.z = 3.0;

 spl3->AddKnot(tmpPnt,1);

 tmpPnt.x = -4.0; tmpPnt.y = 2.0; tmpPnt.z = -1.0;

 spl3->AddKnot(tmpPnt,2);

 tmpPnt.x = -5.0; tmpPnt.y = 3.0; tmpPnt.z = 1.0;

 spl3->AddKnot(tmpPnt,3);

 tmpPnt.x =-5.0; tmpPnt.y = 4.0; tmpPnt.z = 2.0;

 spl3->AddKnot(tmpPnt,4);

 

 sgCSpline* spl3_obj = sgCreateSpline(*spl3);

 SG_SPLINE::Delete(spl3);

 sgGetScene()->AttachObject(spl3_obj);

 spl3_obj->SetAttribute(SG_OA_COLOR,50);

 spl3_obj->SetAttribute(SG_OA_LINE_THICKNESS, 3);

 

This code creates the forth spline:

SG_SPLINE* spl4 = SG_SPLINE::Create();

 

 tmpPnt.x = 4.0; tmpPnt.y = 0.0; tmpPnt.z = 1.0;

 spl4->AddKnot(tmpPnt,0);

 tmpPnt.x = 3.0; tmpPnt.y = 1.0; tmpPnt.z = 2.0;

 spl4->AddKnot(tmpPnt,1);

 tmpPnt.x = 5.0; tmpPnt.y = 2.0; tmpPnt.z = -1.0;

 spl4->AddKnot(tmpPnt,2);

 tmpPnt.x = 3.0; tmpPnt.y = 3.0; tmpPnt.z = 0.5;

 spl4->AddKnot(tmpPnt,3);

 tmpPnt.x =4.0; tmpPnt.y = 4.0; tmpPnt.z = 0.0;

 spl4->AddKnot(tmpPnt,4);

 

 sgCSpline* spl4_obj = sgCreateSpline(*spl4);

 SG_SPLINE::Delete(spl4);

 sgGetScene()->AttachObject(spl4_obj);

 spl4_obj->SetAttribute(SG_OA_COLOR,100);

 spl4_obj->SetAttribute(SG_OA_LINE_THICKNESS, 4);

 

 

Let's create the Coons surface itself:

sgCObject* coons = sgSurfaces::Coons((const sgC2DObject&)*spl1_obj,

                                                                         (const sgC2DObject&)*spl2_obj,

                                                                         (const sgC2DObject&)*spl3_obj,

                                                                         (const sgC2DObject*)spl4_obj,36,36,4,4);

 sgGetScene()->AttachObject(coons);

 coons->SetAttribute(SG_OA_COLOR,4);

 

Then let's move the obtained surface:

 

SG_VECTOR transV1 = {0,0,-0.3};

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

 coons->ApplyTempMatrix();

 coons->DestroyTempMatrix();

 

See also:

sgSurcfaces::Coons  

sgCSpline   SG_SPLINE

sgGetScene sgCScene::AttachObject   sgCObject::SetAttribute

 

Illustration:

coons4