TColgp_Array1OfVec2d tangents( 1, (int)n );
Handle(TColStd_HArray1OfBoolean) flags = new TColStd_HArray1OfBoolean( 1, (int)n );
- for( size_t i = 1; i <= n; i++ )
+ // Stage 1. Orient all profiles to be co-oriented with the first profile
+ theProfiles[0]->Update();
+ for( size_t i = 1; i < n; i++ )
{
- Handle_HYDROData_Profile aProfile = theProfiles[i-1];
- Handle_HYDROData_Profile aPrevProfile = i==1 ? theProfiles[i-1] : theProfiles[i-2];
- Handle_HYDROData_Profile aNextProfile = i==n ? theProfiles[i-1] : theProfiles[i];
+ Handle_HYDROData_Profile aProfile = theProfiles[i];
+ Handle_HYDROData_Profile aPrevProfile = theProfiles[i-1];
- if( !IsCooriented( aProfile, aNextProfile ) )
+ if( !IsCooriented( aProfile, aPrevProfile ) )
{
gp_XY lp, rp;
aProfile->GetLeftPoint( lp, true );
aProfile->SetRightPoint( lp, true );
}
aProfile->Update();
+ }
+
+ // Stage 2. Calculate normals so that each normal "points" to the next profile
+ for( size_t i = 0; i < n; i++ )
+ {
+ Handle_HYDROData_Profile aProfile = theProfiles[i];
+ Handle_HYDROData_Profile aNextProfile = i==n-1 ? theProfiles[i-1] : theProfiles[i+1];
gp_Pnt aLowest;
gp_Vec2d aNormal;
double zmin, zmax;
- gp_XYZ curP = aProfile->GetBottomPoint();
+ gp_XYZ curP = aProfile->GetBottomPoint(true);
gp_XY curP2d = gp_XY(curP.X(), curP.Y());
- gp_XYZ nextP;
- if( i==n )
- nextP = aPrevProfile->GetBottomPoint(true);
- else
- nextP = aNextProfile->GetBottomPoint(true);
-
+ gp_XYZ nextP = aNextProfile->GetBottomPoint(true);
gp_XY nextP2d = gp_XY(nextP.X(), nextP.Y());
gp_Vec2d aPrTangent;
aNormal.SetCoord( -aPrTangent.Y(), aPrTangent.X() );
gp_Vec2d aDirToNextProfile(nextP2d.X() - curP2d.X(), nextP2d.Y() - curP2d.Y() );
- if( i==n )
+ if( i==n-1 )
aDirToNextProfile.Reverse();
+
if (aNormal.Dot(aDirToNextProfile) < 0)
aNormal.Reverse();
aNormal.Normalize();
- points->SetValue( (int)i, gp_Pnt2d( aLowest.X(), aLowest.Y() ) );
- tangents.SetValue( (int)i, aNormal );
- flags->SetValue( (int)i, Standard_True );
+ points->SetValue( (int)(i+1), gp_Pnt2d( aLowest.X(), aLowest.Y() ) );
+ tangents.SetValue( (int)(i+1), aNormal );
+ flags->SetValue( (int)(i+1), Standard_True );
}
Geom2dAPI_Interpolate anInterpolator( points, Standard_False, Standard_False );