[求助]请问在ARX里面怎样判断POLYLINE的走向是顺时针还是逆时针
求助]请问在ARX里面怎样判断POLYLINE的走向是顺时针还是逆时针 <p>经常看到这种问题:)</p><p>可以描述下在什么情况下需要么?</p><p>另外可以试下把DbCurve转换成GeCurve去做复杂的拓扑计算</p> 主要是用于已取得的两条多义线的顶点形成两个LIST后,合并成一个LIST,然后反生成一条多义性,如果原来的两根多义性走向不一样,那知合并LIST会达不到预定目标 <p>置顶贴有一个这样的代码吧,走向不一样有两种方式解决</p><p>1/计算,象置顶贴类似的</p><p>2/转成Ge曲线,Ge曲线有倒置曲线的方法</p><p>另外:如果Cad2010的话DB曲线提供了倒置曲线的方法</p> 下面是一个办法,不过估计楼主没必要去判断POLYLINE的走向是顺时针还是逆时针/// <summary>
/// 判断轻型多义性的时钟走向
/// Version : 2008.11.14
/// </summary>
/// <param name="pline">轻型多义性</param>
/// <returns>顺时针返回-1,逆时针返回1</returns>
static public int Clockwise(Polyline pline)
{
Polyline pline1 = (Polyline)pline.Clone();
double bulge0 = pline1.GetBulgeAt(0);
double area0 = pline1.Area;
if (bulge0 == 0.0)
{
pline1.SetBulgeAt(0, 0.5);
double area1 = pline1.Area;
if (area1 > area0)
return 1;
else
return -1;
}
else
{
pline1.SetBulgeAt(0, 0);
double area1 = pline1.Area;
if (bulge0 > 0)
{
if (area1 > area0)
return -1;
else
return 1;
}
else
{
if (area1 > area0)
return 1;
else
return -1;
}
}
}
使用多段线的1,2 最后一个点三个点创建一个Plane,根据Plane的法向量判断? 学习了。。。 <CommandMethod("test")> _
Public Sub Test()
Dim optEntity As New PromptEntityOptions("选择多段线:")
With optEntity
.SetRejectMessage("所选对象不是多段线")
.AddAllowedClass(GetType(Polyline), False)
.AllowNone = True
End With
Dim resEntity As PromptEntityResult = ed.GetEntity(optEntity)
If resEntity.Status <> PromptStatus.OK Then Return
Dim JingDu As Double = 0.001 '浮点值的比较精度
Using trans As Transaction = db.TransactionManager.StartTransaction
Dim ent As Polyline = trans.GetObject(resEntity.ObjectId, OpenMode.ForRead)
Dim P1 As Point2d = ent.GetPoint2dAt(0)
Dim P2 As Point2d = ent.GetPoint2dAt(1)
Dim Ji As Double = P2.X * P1.Y - P2.Y * P1.X
Dim Message As String
Select Case Ji
Case Is < -JingDu
Message = "第2点在第1点的逆时针方向"
Case Is > JingDu
Message = "第2点在第1点的顺时针方向"
Case Else
Message = "此两点连线通过原点"
End Select
ed.WriteMessage(Message)
End Using
End Sub 本帖最后由 ywlm 于 2011-2-11 22:21 编辑
这样比较简练一点
<CommandMethod("test")> _
Public Sub Test()
Dim optEntity As New PromptEntityOptions("选择多段线:")
With optEntity
.SetRejectMessage("所选对象不是多段线")
.AddAllowedClass(GetType(Polyline), False)
.AllowNone = True
End With
Dim resEntity As PromptEntityResult = ed.GetEntity(optEntity)
If resEntity.Status <> PromptStatus.OK Then Return
Dim JingDu As Double = 0.001 '浮点值的比较精度
Using trans As Transaction = db.TransactionManager.StartTransaction
Dim ent As Polyline = trans.GetObject(resEntity.ObjectId, OpenMode.ForRead)
Dim ji As Vector3d = ent.GetPoint3dAt(1).GetAsVector.CrossProduct(ent.GetPoint3dAt(0).GetAsVector)
Dim Message As String
Select Case ji.Z
Case Is < -JingDu
Message = "第2点在第1点的逆时针方向"
Case Is > JingDu
Message = "第2点在第1点的顺时针方向"
Case Else
Message = "此两点连线通过原点"
End Select
ed.WriteMessage(Message)
End Using
End Sub http://bbs.mjtd.com/thread-81351-1-1.html
页:
[1]
2