通过旋转创建三维(不是灌水!!!)
本帖最后由 作者 于 2004-8-24 10:41:26 编辑 <br /><br /> 请教 通过旋转创建三维,将region对象A桡经过P1(X1,Y1,H1)和P2(X2,Y2,H2)两点的直线L旋转一周用下面函数对吗?<BR>Set solidObj = ThisDrawing.ModelSpace.AddRevolvedSolid(A, P1, P2, 6.28)为什么老创建出圆锥形实体?
致谢<BR> 老大,不是灌水,我试验3天了,region对象A是矩形,直线L平行于A的一条边,我理解应旋转出一圆管型实体,但是老创建出圆锥形,求解!!!! 你先灌水了,开始是什么? rrrr
把完整的代码贴上来 Sub view_3d()
'On Error Resume Next<BR> <BR> Dim sset As AcadSelectionSet<BR> Dim seledobj As Object
ThisDrawing.SelectionSets("SS1").Delete<BR> Set sset = ThisDrawing.SelectionSets.Add("SS1")<BR> On Error GoTo 0<BR> DoEvents<BR> sset.SelectOnScreen<BR>
'================================================
' Dim sset As Object<BR>' Set sset = ThisDrawing.SelectionSets.Item("SS1")<BR>
Dim ent As AcadEntity<BR> <BR> For Each ent In sset<BR> If TypeName(ent) = "IAcadLine" Then<BR> S_P = ent.StartPoint<BR> e_p = ent.EndPoint<BR> ang = ent.angle<BR> houdu = 0.1<BR> AddRevolvedSolid S_P(0), S_P(1), S_P(2), e_p(0), e_p(1), e_p(2), ang, 500, houdu<BR> End If<BR> Next ent
End Sub
Sub AddRevolvedSolid(ByVal x1 As Double, ByVal y1 As Double, ByVal h1 As Double, _<BR> ByVal x2 As Double, ByVal y2 As Double, ByVal h2 As Double, _<BR> ByVal jiaodu As Double, _<BR> banjing As Double, _<BR> ByVal houdu As Double)<BR>linex1 = x1: liney1 = y1: lineh1 = h1<BR>linex2 = x2: liney2 = y2: lineh2 = h2
<BR> <BR> <BR> <BR> x1 = linex1 + banjing * Sin(jiaodu): y1 = liney1 - banjing * Cos(jiaodu): h1 = lineh1<BR> x2 = linex2 + banjing * Sin(jiaodu): y2 = liney2 - banjing * Cos(jiaodu): h2 = lineh2<BR> <BR> ' This example creates a solid from a region<BR> ' rotated around an axis.<BR> ' The region is created from an arc and a line.<BR> Dim curves(0 To 3) As AcadEntity<BR> ' Define the line
Dim start_p(0 To 2) As Double<BR> Dim end_p(0 To 2) As Double<BR> Dim radius As Double<BR> Dim startAngle As Double<BR> Dim endAngle As Double<BR> <BR> <BR> start_p(0) = x1: start_p(1) = y1: start_p(2) = h1<BR> end_p(0) = x2: end_p(1) = y2: end_p(2) = h2<BR> Set curves(0) = ThisDrawing.ModelSpace.AddLine(start_p, end_p)
start_p(0) = x2: start_p(1) = y2: start_p(2) = h2<BR> end_p(0) = x2 - houdu * Sin(jiaodu): end_p(1) = y2 + houdu * Cos(jiaodu): end_p(2) = h2<BR> Set curves(1) = ThisDrawing.ModelSpace.AddLine(start_p, end_p)
start_p(0) = x2 - houdu * Sin(jiaodu): start_p(1) = y2 + houdu * Cos(jiaodu): start_p(2) = h2<BR> end_p(0) = x1 - houdu * Sin(jiaodu): end_p(1) = y1 + houdu * Cos(jiaodu): end_p(2) = h1<BR> Set curves(2) = ThisDrawing.ModelSpace.AddLine(start_p, end_p)
start_p(0) = x1 - houdu * Sin(jiaodu): start_p(1) = y1 + houdu * Cos(jiaodu): start_p(2) = h1<BR> end_p(0) = x1: end_p(1) = y1: end_p(2) = h1<BR> Set curves(3) = ThisDrawing.ModelSpace.AddLine(start_p, end_p)<BR> <BR> <BR> ' Create the region<BR> Dim regionObj As Variant<BR> regionObj = ThisDrawing.ModelSpace.AddRegion(curves)<BR> regionObj(0).Color = acCyan<BR> ' MsgBox "Revolve the region to create the solid.", , "AddRevolvedSolid Example"<BR> <BR> ' Define the rotation axis<BR> Dim axisPt(0 To 2) As Double<BR> Dim axisDir(0 To 2) As Double<BR> Dim angle As Double<BR> axisPt(0) = linex1: axisPt(1) = liney1: axisPt(2) = lineh1<BR> <BR> axisDir(0) = linex2: axisDir(1) = liney2: axisDir(2) = lineh2<BR> angle = 6.28<BR> <BR> ' Create the solid<BR> Dim solidObj As Acad3DSolid<BR> Set solidObj = ThisDrawing.ModelSpace.AddRevolvedSolid(regionObj(0), axisPt, axisDir, angle)<BR> solidObj.Color = acRed
<BR>' ' Change the viewing direction of the viewport<BR>' Dim NewDirection(0 To 2) As Double<BR>' NewDirection(0) = -1: NewDirection(1) = -1: NewDirection(2) = 1<BR>' ThisDrawing.ActiveViewport.Direction = NewDirection<BR>' ThisDrawing.ActiveViewport = ThisDrawing.ActiveViewport<BR>' ZoomAll<BR>' MsgBox "Solid created.", , "AddRevolvedSolid Example"
End Sub
画一条三维直线试验
老大,看看是不是思想问题
<BR> <P class=syntax>RetVal = object.AddRevolvedSolid(Profile, AxisPoint, AxisDir, Angle)
<P class=element>Object
<P class=element-desc><A href="mk:@MSITStore:D:\Program%20Files\AutoCAD%202005\help\acadauto.chm::/idh_modelspace_collection.htm" target="_blank" >ModelSpace Collection</A>, <A href="mk:@MSITStore:D:\Program%20Files\AutoCAD%202005\help\acadauto.chm::/idh_paperspace_collection.htm" target="_blank" >PaperSpace Collection</A>, <A href="mk:@MSITStore:D:\Program%20Files\AutoCAD%202005\help\acadauto.chm::/idh_block_object.htm" target="_blank" >Block</A><BR>The object or objects this method applies to.
<P class=element>Profile
<P class=element-desc><A href="mk:@MSITStore:D:\Program%20Files\AutoCAD%202005\help\acadauto.chm::/idh_region_object.htm" target="_blank" >Region</A> object; input-only
<P class=element>AxisPoint<BR>Variant (three-element array of doubles); input-only<BR>The 3D WCS coordinates specifying the start point of the axis of revolution. <BR>AxisDir<BR>Variant (three-element array of doubles); input-only<BR>A 3D vector specifying the direction of the axis of revolution.
<P class=element>Angle
<P class=element-desc>Double; input-only<BR>The angle of revolution in radians. Enter 6.28 for a full circle revolution.
<P class=element>RetVal
<P class=element-desc><A href="mk:@MSITStore:D:\Program%20Files\AutoCAD%202005\help\acadauto.chm::/idh_3dsolid_object.htm" target="_blank" >3DSolid</A> object<BR>A 3DSolid object as the newly created revolved solid. RetVal = object.AddRevolvedSolid(Profile, AxisPoint, AxisDir, Angle) <BR>帮助我看过了AxisPoint是旋转轴起点, AxisDir是旋转轴方向点,对于将region对象A桡经过P1(X1,Y1,H1)和P2(X2,Y2,H2)两点的直线L旋转一周不是Set solidObj = ThisDrawing.ModelSpace.AddRevolvedSolid(A, P1, P2, 6.28) 吗?
完整代码第四楼,能帮我试试吗?实在没辙了<BR> p2(x2-x1,y2-y1,z2-z1) 太感谢了,向无私奉献的人致敬
页:
[1]