|
块的角度[code] static void CreateAngleOfBlk()
{
if (m_BlockRef)
{
delete m_BlockRef;
m_BlockRef = nullptr;
}
m_DirPt = dir_pt;
m_BlockRef = new AcDbBlockReference();
m_BlockRef->setBlockTableRecord(blk_objid);
// Calcualte Normal : refactor as function
AcGeVector3d vec = endPoint().asVector() - startPoint().asVector();
AcGeVector3d vec1 = m_DirPt.asVector() - startPoint().asVector();
AcGeVector3d vec_normal = vec.crossProduct(vec1);
vec_normal.normalize();
// Get UCS, refactor as a function
AcGeMatrix3d myUCS;
acdbUcsMatrix(myUCS, nullptr);
AcGeVector3d xAxis, yAxis, zAxis;
AcGePoint3d myOrigin;
myUCS.getCoordSystem(myOrigin, xAxis, yAxis, zAxis);
bool AngleFlip = false;
if (fabs(vec_normal.dotProduct(zAxis)) < 1e-8)
return;
else if (vec_normal.dotProduct(zAxis) < 0)
AngleFlip = true;
else
AngleFlip = false;
m_BlockRef->setNormal(zAxis); //(vec_normal);
m_BlockRef->setPosition(ins_pt);
AcGeScale3d scl;
if (scale < 0)
scale = 1.0;
scl.set(scale, scale, scale);
m_BlockRef->setScaleFactors(scl);
// calculate angle
ads_point p_start_wcs, p_end_wcs, p_start_ucs, p_end_ucs;
p_start_wcs[X] = startPoint().x; p_start_wcs[Y] = startPoint().y; p_start_wcs[Z] = startPoint().z;
p_end_wcs[X] = endPoint().x; p_end_wcs[Y] = endPoint().y; p_end_wcs[Z] = endPoint().z;
ConvertFromWCSToUCS(p_start_wcs, p_start_ucs);
ConvertFromWCSToUCS(p_end_wcs, p_end_ucs);
AcGePoint3d p_start(p_start_ucs[X], p_start_ucs[Y], p_start_ucs[Z]);
AcGePoint3d p_end(p_end_ucs[X], p_end_ucs[Y], p_end_ucs[Z]);
AcGeVector3d v1_ucs = p_end.asVector() - p_start.asVector();
AcGeVector3d v1 = endPoint().asVector() - startPoint().asVector();
AcGeVector3d ref_vector = AcGeVector3d::kZAxis;
double dangle = xAxis.angleTo(v1_ucs, zAxis); // this is not what I want?
double dangle1 = AcGeVector3d::kXAxis.angleTo(v1_ucs, AcGeVector3d::kZAxis);
if (m_AngleFlip)
{
dangle1 *= -1;
m_FlipHandle = !m_FlipHandle;
}
m_BlockRef->setRotation(dangle1);
}
[/code] |
|