void RoundPolygonVertices( VERTEXES& vcVertexes, double dRound )
{
VERTEXES vt;
CVertex v0,v1;
long lCount = vcVertexes.size();
for( int i = 0; i < lCount; ++i )
{
if(i)
{
double dLength = Magnitude(vcVertexes[i], vcVertexes[i-1]);
double slope=(vcVertexes[i].dY-vcVertexes[i-1].dY)/(vcVertexes[i].dX-vcVertexes[i-1].dX);
double slopeAngle;
if(!_isnan(slope))
slopeAngle=atan(slope);
else
{
slope=0;
slopeAngle=0;
}
if( dLength > 0.0 && dRound > 0.0 )
{
if(fmod( dLength, dRound) > 0)
{
double dUpper, dLower;
dLower = floor(dLength / dRound) * dRound;
dUpper = dLower+dRound;
if((dLength-dLower) >= (dUpper-dLength))
dLength=dUpper;
else
dLength=dLower;
}
v1=vcVertexes[i]-vcVertexes[i-1];
if(v1.dX)
v1.dX=v1.dX/fabs(v1.dX);
if(v1.dY)
v1.dY=v1.dY/fabs(v1.dY);
v1.dY=v1.dY*fabs(sin(slopeAngle)*dLength);
v1.dX=v1.dX*fabs(cos(slopeAngle)*dLength);
v0=v1+v0;
}
vt.push_back(v0);
}
else
vt.push_back( v0 );
}
vcVertexes.clear();
vcVertexes.insert( vcVertexes.begin(), vt.begin(), vt.end() );
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
Dynamically allocate memory | 9 | 56 | |
mapAB Challlenge | 35 | 123 | |
STDEVP in SQL | 2 | 54 | |
x-bar in Google Sheets | 2 | 24 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
12 Experts available now in Live!