引言:Revit二次开发中,投影、求交点是很重要的东西,笔者经过多次运用,发现以下两个是笔者常用的,分享给大家。希望诸君多多支持。————笔者有贰法,与君共勉之,云云🤭
/// <summary>
/// 投影到一个平面
/// </summary>
/// <param name=""></param>
/// <param name="xyz"></param>
/// <returns></returns>
public static XYZ GetProjectPoint(Plane plane, XYZ xyz)
{
Transform tf = Transform.Identity;
tf.BasisX = plane.XVec;
tf.BasisY = plane.YVec;
tf.BasisZ = plane.Normal;
tf.Origin = plane.Origin;
XYZ p = tf.Inverse.OfPoint(xyz);
p = new XYZ(p.X, p.Y, 0);
return tf.OfPoint(p);
}
/// <summary>
/// 计算两条线的交点
/// </summary>
/// <param name="curve1"></param>
/// <param name="curve2"></param>
/// <returns></returns>
///
public static XYZ IntersectionPoint(Curve curve1, Curve curve2)
{
IntersectionResultArray intersectionR = new IntersectionResultArray();
SetComparisonResult comparisonR;
comparisonR = curve1.Intersect(curve2, out intersectionR);
XYZ intersectionResult = null;
if (SetComparisonResult.Disjoint != comparisonR) // Disjoint无交点
{
try
{
if (!intersectionR.IsEmpty)
{
intersectionResult = intersectionR.get_Item(0).XYZPoint;
}
}
catch
{ }
}
return intersectionResult;
}
技术群:1090519856