-1
1-我怎樣才能找到在x,yI斜牆角度使用下面的代碼找到它的牆壁,但它不適用於傾斜牆壁。 當我將它用於普通牆時,它給出的XYz類似於0,1,0/0,-1,0/1,0,0/-1,0,0 ,但對於傾斜的牆它變成了0,0, 1所有的時間。請閱讀代碼。 2-我想在我的Revit項目中使用 API找到門窗的Id。我可以在牆上找到開口,但實際需要的卻完全相反,我需要主持人。斜壁方向和門窗主機revit api
protected XYZ GetExteriorWallDirection(Element wall)
{
LocationCurve locationCurve
= wall.Location as LocationCurve;
XYZ exteriorDirection = XYZ.BasisZ;
if (locationCurve != null)
{
Curve curve = locationCurve.Curve;
//Write("Wall line endpoints: ", curve);
XYZ direction = XYZ.BasisX;
if (curve is Line)
{
// Obtains the tangent vector of the wall.
direction = curve.ComputeDerivatives(
0, true).BasisX.Normalize();
}
else
{
// An assumption, for non-linear walls,
// that the "tangent vector" is the direction
// from the start of the wall to the end.
direction = (curve.GetEndPoint(1)
- curve.GetEndPoint(0)).Normalize();
}
// Calculate the normal vector via cross product.
exteriorDirection = getCrossProduct(XYZ.BasisZ,direction);
// Flipped walls need to reverse the calculated direction
Wall wa = wall as Wall;
if (wa.Flipped)
{
exteriorDirection = -exteriorDirection;
}
}
return exteriorDirection;
}
protected XYZ getCrossProduct(XYZ a, XYZ b)
{
double ax = a.X;
double ay = a.Y;
double az = a.Z;
double bx = b.X;
double by = b.Y;
double bz = b.Z;
double cx = ay * bz - az * by;//= 3×7 − 4×6 = −3
double cy = az * bx - ax * bz;//= 4×5 − 2×7 = 6
double cz = ax * by - ay * bx;// = 2×6 − 3×5 = −3
XYZ c = new XYZ(cx, cy, cz);
return c;
}