如何获取两条直线的交点?
如何获取两条直线的交点?有什么函数吗?还有,对多段线进行内部填充时多段线必须是封闭的吗? public virtual void IntersectWith(Autodesk.AutoCAD.DatabaseServices.Entity entityPointer, Autodesk.AutoCAD.DatabaseServices.Intersect intersectType, Autodesk.AutoCAD.Geometry.Point3dCollection points, int thisGraphicSystemMarker, int otherGraphicSystemMarker)Autodesk.AutoCAD.DatabaseServices.Entity 的成员
public virtual void IntersectWith(Autodesk.AutoCAD.DatabaseServices.Entity entityPointer, Autodesk.AutoCAD.DatabaseServices.Intersect intersectType, Autodesk.AutoCAD.Geometry.Plane projectionPlane, Autodesk.AutoCAD.Geometry.Point3dCollection points, int thisGraphicSystemMarker, int otherGraphicSystemMarker)
Autodesk.AutoCAD.DatabaseServices.Entity 的成员 是要求曲线组成一个封闭区域,若是一个多义线则要求多义线是封闭的,也可以多个不封闭的多义线相连成一个封闭轮廓。 回复
这两个函数好难看懂啊!那我也可以写一个方法来求线段的交点吧? http://379910987.blog.163.com/bl ... 972010111612020453/
呵呵,当然,所有的函数都是人写出来的,别人可以,当然你也可以!
下面是个示意,希望能帮到你。
///
/// 求两条曲线的交点,本函数为应对Polyline.IntersectWith函数的Bug
/// Vrsion : 2009.02.10 Sieben
/// Vrsion : 2010.12.25 增加判断输入实体是否为平面实体
///
///
///
///
public static Point3dCollection IntersectWith(Entity ent1, Entity ent2, Intersect intersectType)
{
try
{
if (ent1 is Polyline || ent2 is Polyline)
{
if (ent1 is Polyline && ent2 is Polyline)
{
Polyline pline1 = (Polyline)ent1;
Polyline pline2 = (Polyline)ent2;
return IntersectWith(pline1.ConvertTo(false), pline2.ConvertTo(false), intersectType);
}
else if (ent1 is Polyline)
{
Polyline pline1 = (Polyline)ent1;
return IntersectWith(pline1.ConvertTo(false), ent2, intersectType);
}
else
{
Polyline pline2 = (Polyline)ent2;
return IntersectWith(ent1, pline2.ConvertTo(false), intersectType);
}
}
else
{
Point3dCollection interPs = new Point3dCollection();
if (ent1.IsPlanar && ent2.IsPlanar)
ent1.IntersectWith(ent2, intersectType, new Plane(Point3d.Origin, Vector3d.ZAxis), interPs, 0, 0);
else
ent1.IntersectWith(ent2, intersectType, interPs, 0, 0);
return interPs;
}
}
catch (System.Exception ex)
{
return null;
}
} ///
/// 求两两连线的交点
///
/// 第一组点
/// 第一组点
/// 第二组点
/// 第二组点
/// 若有交点就返回交点,否则返回P11
static public Point3d PLL(Point3d P11, Point3d P12, Point3d P21, Point3d P22)
{
double A1 = P12.Y - P11.Y;
double B1 = P11.X - P12.X;
double C1 = -A1 * P11.X - B1 * P11.Y;
double A2 = P22.Y - P21.Y;
double B2 = P21.X - P22.X;
double C2 = -A2 * P21.X - B2 * P21.Y;
double dlt = A1 * B2 - A2 * B1;
double dltx = C1 * B2 - C2 * B1;
double dlty = A1 * C2 - A2 * C1;
if (Math.Abs(dlt) < 0.00000001)
{
return P11;
}
else
{
return new Point3d(-1.0 * (dltx / dlt), -1.0 * (dlty / dlt), 0);
}
}
注意,直线的交点和直线段的交点是有区别的 回复
你是武大的?呵呵 回复
谢谢sieben,对我来说很有用。 非常感谢!
页:
[1]