Coons surface by three boundary contours.
Let's create a Coons surface by three boundary contours - two splines and one arc.
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 = -1.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 = -6.0; tmpPnt.y = 0.0; tmpPnt.z = -1.0;
spl2->AddKnot(tmpPnt,0);
tmpPnt.x = -6.0; tmpPnt.y = 0.5; tmpPnt.z = 0.0;
spl2->AddKnot(tmpPnt,1);
tmpPnt.x = -6.0; tmpPnt.y = 2.0; tmpPnt.z = -1.0;
spl2->AddKnot(tmpPnt,2);
tmpPnt.x = -6.0; tmpPnt.y = 3.0; tmpPnt.z = 1.0;
spl2->AddKnot(tmpPnt,3);
tmpPnt.x =-4.0; tmpPnt.y = 4.0; tmpPnt.z = 1.0;
spl2->AddKnot(tmpPnt,4);
sgCSpline* spl2_obj = sgCreateSpline(*spl2);
SG_SPLINE::Delete(spl2);
sgGetScene()->AttachObject(spl2_obj);
spl2_obj->SetAttribute(SG_OA_COLOR,50);
spl2_obj->SetAttribute(SG_OA_LINE_THICKNESS, 3);
This code creates the arc:
SG_POINT ArP1;
SG_POINT ArP2;
SG_POINT ArP3;
SG_ARC ArcGeo;
ArP1.x = -4.0; ArP1.y = 4.0; ArP1.z = 1.0;
ArP2.x = 4.0; ArP2.y = 0.0; ArP2.z = 1.0;
ArP3.x = 0.0; ArP3.y = 5.0; ArP3.z = -4.0;
ArcGeo.FromTreePoints(ArP1,ArP2,ArP3,false);
sgCArc* arcObj = sgCreateArc(ArcGeo);
Let's create the Coons surface itself:
sgCObject* coons = sgSurfaces::Coons((const sgC2DObject&)*spl1_obj,
(const sgC2DObject&)*spl2_obj,
(const sgC2DObject&)*arcObj,
NULL,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.4};
coons->InitTempMatrix()->Translate(transV1);
coons->ApplyTempMatrix();
coons->DestroyTempMatrix();
See also:
sgGetScene sgCScene::AttachObject sgCObject::SetAttribute
Illustration: