zxlllw 发表于 2007-10-4 09:06:00

如何获得直线的倾斜角度.谢谢啊

如何获得直线的倾斜角度?本人想实现得到,选择的直线的,倾斜角度,做为另外对象的参照.谢谢.有代码例子更好.

zzcctt 发表于 2007-10-4 14:29:00

<p>告诉你实现的方法,代码你自己写一下,很简单的</p><p>1,获取直线,可以得到直线的两个端点</p><p>2,根据两点,</p><pre class="Code">Sub Example_AngleFromXAxis()
    ' This example finds the angle, in radians, between the X axis
    ' and a line defined by two points.
      
    Dim pt1(0 To 2) As Double
    Dim pt2(0 To 2) As Double
    Dim retAngle As Double
      
    pt1(0) = 2:pt1(1) = 5:pt1(2) = 0
    pt2(0) = 5:pt2(1) = 2:pt2(2) = 0
      
    ' Return the angle
    retAngle = ThisDrawing.Utility.AngleFromXAxis(pt1, pt2)
      
    ' Create the line for a visual reference
    Dim lineObj As AcadLine
    Set lineObj = ThisDrawing.ModelSpace.AddLine(pt1, pt2)
    ZoomAll
      
    ' Display the angle found
    MsgBox "The angle in radians between the X axis and the line is " &amp; retAngle, , "AngleFromXAxis Example"
      
End Sub</pre><pre class="Code">3,角度算出了(是以PI表示),根据自己的需要进行转换</pre>

zxlllw 发表于 2007-10-4 16:29:00

谢谢,我是新手,有个问题,就是vba在有窗体运行的时候,是不能再去选择已经画的图形进行编辑的了...头大。有没有什么方法,比如说,我要在3条直线相交的三角形里面加一行文字,那么我要在运行程序后,去选择3条直线,但是vba这点好想办不到?能方法的话,请各位大大介绍下,小生,先谢过。

dfgs 发表于 2007-10-4 20:46:00

<p>你这后面的问题其实比较简单,如果要手工选择那三条线的话,可以将窗体先隐藏,me.hide,然后用选择集执行屏幕选择,SelectOnScreen。最后计算三条直线的交点,<span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">IntersectWith,就可以计算出文字需要的坐标。最后重新显示窗口,me.show</span></p><p><span lang="EN-US" style="FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: 宋体; mso-bidi-font-family: 'Courier New'; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;">如果不是手工选择三条直线,你就要说明如何确定需要的直线,大家才好解答。</span></p>

英雄无敌 发表于 2007-10-5 15:59:00

如果是直线,直接用line.angle就可以返回角度,不过为弧度。

兰州人 发表于 2007-10-12 11:46:00

<p>帮助文件有实例</p><pre class="Code">Sub Example_Angle()
   ' This example adds a line in model space and returns the angle of the new line
   
    Dim lineObj As AcadLine
    Dim startPoint(0 To 2) As Double, endPoint(0 To 2)As Double
   
    ' Define the start and end points for the line
    startPoint(0) = 1: startPoint(1) = 1: startPoint(2) = 0
    endPoint(0) = 5: endPoint(1) = 5: endPoint(2) = 0
   
    ' Create the line in model space
    Set lineObj = ThisDrawing.ModelSpace.AddLine(startPoint, endPoint)

    ThisDrawing.Application.ZoomAll
   
    MsgBox "The angle of the new Line is: " &amp; lineObj.angle
End Sub</pre>

edi-000 发表于 2007-10-16 11:40:00

如果是一张已知的CAD图,如何选择其中一条样条曲线,然后得到其拟合点的坐标值呢?谢谢
页: [1]
查看完整版本: 如何获得直线的倾斜角度.谢谢啊