|
////////////////////////////////////////////////////////////////////////////////
/////// 将球在圆上分成m_nPrecision段,然后求相应处圆的半径 ///////
/////// 再将此圆分成m_nPrecision份。 ////////
/////// 所以共 (m_nPrecision+1)*(m_nPrecision+1)个点 ////
////////////////////////////////////////////////////////////////////////////////
Acad::ErrorStatus PDSphere::getVertices(int Precision, AcGePoint3dArray& vertexArray,
AcGeIntArray &stdIdx, int &actPrecision) const
{ assertReadEnabled();
while(!vertexArray.isEmpty())
vertexArray.removeLast();
AcGeDoubleArray dividDbl;
getActDivid(Precision, dividDbl, stdIdx);
int actPrecision__1 = dividDbl.length();
int actPrecision___2__1 = (dividDbl.length() - 1) * 2 + 1;
actPrecision = actPrecision__1 - 1;
vertexArray.setLogicalLength(actPrecision__1*actPrecision___2__1);
AcGePoint3d varPt = m_ptCenter; //变截面的中心点
double varR = 0;
double deltaAngle = PI / Precision;
/////////////////////////////////////////////////////////////
/////// begin the division /////////
AcGeCubicSplineCurve3d varcur;
AcGePoint3d point;
for(int i = 0; i < actPrecision__1; ++i)
{
varPt.z=m_ptCenter.z- m_dRadius*cos(deltaAngle*dividDbl[i]);
double tt = m_dRadius * m_dRadius - (m_ptCenter.z - varPt.z) *
(m_ptCenter.z - varPt.z);
if(tt < 0)
tt = 0;
varR = sqrt(tt);
int j;
for(j = 0; j <actPrecision__1; ++j)
{
if(i == 0)
{
point = m_ptCenter - AcGeVector3d(0, 0, 1) * m_dRadius;
vertexArray[i*actPrecision___2__1+j]=point;
}
else if(i == actPrecision__1)
{
point = m_ptCenter + AcGeVector3d(0, 0, 1) * m_dRadius;
vertexArray[i*actPrecision___2__1+j]=point;
}
else
{
point=varPt + AcGeVector3d(1, 0, 0) * varR;
point.rotateBy(deltaAngle * dividDbl[j], AcGeVector3d(0, 0, 1), varPt);
vertexArray[i*actPrecision__1+j]=point;
}
}
for(j = 1; j <actPrecision__1; ++j)
{
if(i == 0)
{
point = m_ptCenter - AcGeVector3d(0, 0, 1) * m_dRadius;
vertexArray[i*actPrecision__1 + j + actPrecision]=point;
}
else if(i == actPrecision__1)
{
point = m_ptCenter + AcGeVector3d(0, 0, 1) * m_dRadius;
vertexArray[i*actPrecision__1 + j + actPrecision]=point;
}
else
{
point=varPt + AcGeVector3d(1, 0, 0) * varR;
point.rotateBy(deltaAngle * dividDbl[j] + PI, AcGeVector3d(0, 0, 1), varPt);
vertexArray[i*actPrecision__1 + j + actPrecision]=point;
}
}
}
return Acad::eOk;
} |
|