乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 9|回复: 5

[编程交流] vb中的2d数组。网

[复制链接]

15

主题

46

帖子

31

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-6 12:49:54 | 显示全部楼层 |阅读模式
你好
我有一个问题,如何创建一个包含直线起点和终点的数组
 
表(0)[pt1 pt2]第一行
表(1)[pt1 pt2]第二行
 
我应该使用这样的东西吗?它可以工作,但这些点都在一起,所以它并不完美
 
  1. Dim Tab() As Point3d
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 13:03:08 | 显示全部楼层
有几种方法可以存储与点相关的坐标,最佳选择可能取决于数据的下游要求。
 
数组是一种有效的选择,从计算机处理的角度来看,它甚至可能是最有效的。然而,如果点的类型和数量未知,那么对于编码器来说,数组有点少。
 
Autodesk。AutoCAD。几何学Point3dCollection非常易于使用,因为可以随意添加和减去点。
 
关于集合(及其一般易用性),系统。收藏。通用名称空间提供了几种其他存储点(或与此相关的任何数据)的方法,并具有使代码更通用的附加好处,即不仅限于AutoCAD例程。
回复

使用道具 举报

15

主题

46

帖子

31

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-6 13:18:50 | 显示全部楼层
好啊
我试试thx
回复

使用道具 举报

15

主题

46

帖子

31

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-6 13:32:35 | 显示全部楼层
我认为不需要创建新线程,所以我会在这里问你,你知道为什么函数中的光线在图形中不可见吗?如果我使用没有函数的代码,它可以正常工作
 
  1.     <CommandMethod("src")> _
  2.   Public Sub src()
  3.        Dim lCmd As Editor = Application.DocumentManager.MdiActiveDocument.Editor
  4.        Dim acBaza As Database = lCmd.Document.Database
  5.        Dim trn As Transaction = acBaza.TransactionManager.StartTransaction
  6.        Dim lnL1 As Line = New Line()
  7.        Dim usrPtOp As PromptPointOptions = New PromptPointOptions("Wskarz srodek pomieszczenia :")
  8.        Dim usrPt As PromptPointResult = lCmd.GetPoint(usrPtOp)
  9.        Dim prevPt As Point3d = usrPt.Value
  10.        Dim nextPt As Point3d = usrPt.Value
  11.        If usrPt.Status = PromptStatus.OK Then
  12.            Dim usrPtXmod As Point3d = New Point3d(usrPt.Value.X + 1, usrPt.Value.Y, usrPt.Value.Z)
  13.            Dim promienSledzacy As Ray = New Ray()
  14.            promienSledzacy.BasePoint = usrPt.Value
  15.            promienSledzacy.SecondPoint = usrPtXmod
  16.            'FILTRACJA LINII
  17.            Dim typeValue() As TypedValue = {New TypedValue(0, "line")}
  18.            Dim selFilter As SelectionFilter = New SelectionFilter(typeValue)
  19.            Dim selResult As PromptSelectionResult = lCmd.SelectAll(selFilter)
  20.            Dim ssLinie As SelectionSet = selResult.Value
  21.            Dim tabID() As ObjectId = ssLinie.GetObjectIds
  22.            Dim lnNajblizsza As Line = Nothing
  23.            'TRANSAKCJA
  24.            przecieciaPromienia(promienSledzacy, tabID, prevPt, nextPt, lnNajblizsza)
  25.            'Sprawdzenie ktury punkt jest nizej
  26.            Dim START As Point3d
  27.            Dim FIN As Point3d
  28.            If lnNajblizsza.StartPoint.Y > lnNajblizsza.EndPoint.Y Then
  29.                START = lnNajblizsza.EndPoint
  30.            Else
  31.                START = lnNajblizsza.StartPoint
  32.            End If
  33.        End If
  34.    End Sub
  35.    Public Sub przecieciaPromienia(ByRef promienSledzacy As Ray, ByRef tabID() As ObjectId, ByRef prevPt As Point3d, ByRef nextPt As Point3d, ByRef lnNajblizsza As Line)
  36.        Dim lCmd As Editor = Application.DocumentManager.MdiActiveDocument.Editor
  37.        Dim acBaza As Database = lCmd.Document.Database
  38.        Dim trn As Transaction = acBaza.TransactionManager.StartTransaction
  39.        Try
  40.            Dim btr As BlockTableRecord = trn.GetObject(acBaza.CurrentSpaceId, OpenMode.ForWrite)
  41.            Dim objID As ObjectId
  42.            Dim ra3d As Ray3d = New Ray3d(promienSledzacy.StartPoint, promienSledzacy.SecondPoint)
  43.            Dim odl As Single = 0.0
  44.            Dim odlTmp As Single = 0.0
  45.            For Each objID In tabID
  46.                Dim ln As Line = CType(trn.GetObject(objID, OpenMode.ForRead), Line)
  47.                Dim ls As LineSegment3d = New LineSegment3d(ln.StartPoint, ln.EndPoint)
  48.                Dim ptArray() As Point3d = ls.IntersectWith(ra3d)
  49.                If ptArray Is Nothing Then Continue For
  50.                Dim ptkPrzeciecia As Point3dCollection = New Point3dCollection(ptArray)
  51.                'SZUKANIE PIERWSZEJ NAJBLIZSZEJ LINII   
  52.                '   odl=sqrt ((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))
  53.                odlTmp = Math.Sqrt((prevPt.X - ptkPrzeciecia.Item(0).X) * (prevPt.X - ptkPrzeciecia.Item(0).X) + (prevPt.Y - ptkPrzeciecia.Item(0).Y) * (prevPt.Y - ptkPrzeciecia.Item(0).Y))
  54.                If odl = 0.0 Then
  55.                    odl = odlTmp
  56.                    nextPt = ptkPrzeciecia.Item(0)
  57.                    lnNajblizsza = ln
  58.                ElseIf odl >= odlTmp Then
  59.                    nextPt = ptkPrzeciecia.Item(0)
  60.                    lnNajblizsza = ln
  61.                End If
  62.            Next
  63.            lnNajblizsza.Highlight()
  64.            promienSledzacy.SetDatabaseDefaults()
  65.            btr.AppendEntity(promienSledzacy)
  66.            trn.AddNewlyCreatedDBObject(promienSledzacy, True)
  67.            trn.Commit()
  68.        Catch ex As Exception
  69.        Finally
  70.            trn.Dispose()
  71.        End Try
  72.    End Sub
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 13:39:33 | 显示全部楼层
我不能确切地说这是一种确定的方法,但在子/函数之间传递开放数据库对象引用可能不是最佳做法。我修改了结构以说明另一种选择。注意:Autodesk。AutoCAD。几何体对象不是数据库驻留对象
 
我认为Ray没有显示的原因是顶级事务尚未提交。我再次修改了例程来说明这一点。
 
 
  1.     <CommandMethod("src")> _
  2.   Public Sub src()
  3.        Dim lCmd As Editor = Application.DocumentManager.MdiActiveDocument.Editor
  4.        Dim acBaza As Database = lCmd.Document.Database
  5.        Using trn As Transaction = acBaza.TransactionManager.StartTransaction
  6.            Dim lnL1 As Line = New Line()
  7.            Dim usrPtOp As PromptPointOptions = New PromptPointOptions("Wskarz srodek pomieszczenia :")
  8.            Dim usrPt As PromptPointResult = lCmd.GetPoint(usrPtOp)
  9.            Dim prevPt As Point3d = usrPt.Value
  10.            Dim nextPt As Point3d = usrPt.Value
  11.            If usrPt.Status = PromptStatus.OK Then
  12.                Dim usrPtXmod As Point3d = New Point3d(usrPt.Value.X + 1, usrPt.Value.Y, usrPt.Value.Z)
  13.                Dim ls3d As LineSegment3d = New LineSegment3d(usrPt.Value, usrPtXmod)
  14.                'FILTRACJA LINII
  15.                Dim typeValue() As TypedValue = {New TypedValue(0, "line")}
  16.                Dim selFilter As SelectionFilter = New SelectionFilter(typeValue)
  17.                Dim selResult As PromptSelectionResult = lCmd.SelectAll(selFilter)
  18.                Dim ssLinie As SelectionSet = selResult.Value
  19.                Dim tabID() As ObjectId = ssLinie.GetObjectIds
  20.                Dim oid As ObjectId
  21.                'TRANSAKCJA
  22.                oid = przecieciaPromienia(ls3d, tabID, prevPt, nextPt)
  23.                Dim lnNajblizsza As Line = CType(trn.GetObject(oid, OpenMode.ForRead), Line)
  24.                'Sprawdzenie ktury punkt jest nizej
  25.                Dim START As Point3d
  26.                'Dim FIN As Point3d
  27.                If lnNajblizsza.StartPoint.Y > lnNajblizsza.EndPoint.Y Then
  28.                    START = lnNajblizsza.EndPoint
  29.                Else
  30.                    START = lnNajblizsza.StartPoint
  31.                End If
  32.            End If
  33.            trn.Commit()
  34.        End Using
  35.    End Sub
  36.    Public Function przecieciaPromienia(ByRef ls3d As LineSegment3d, ByRef tabID() As ObjectId, ByRef prevPt As Point3d, ByRef nextPt As Point3d) As ObjectId
  37.        Dim lCmd As Editor = Application.DocumentManager.MdiActiveDocument.Editor
  38.        Dim acBaza As Database = Application.DocumentManager.MdiActiveDocument.Database
  39.        Dim lnNajblizsza As Line = Nothing
  40.        Using trn As Transaction = acBaza.TransactionManager.StartTransaction
  41.            Try
  42.                Dim btr As BlockTableRecord = CType(trn.GetObject(acBaza.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
  43.                Dim objID As ObjectId
  44.                Dim ra3d As Ray3d = New Ray3d(ls3d.StartPoint, ls3d.EndPoint)
  45.                Dim odl As Single = 0.0
  46.                Dim odlTmp As Single = 0.0
  47.                For Each objID In tabID
  48.                    Dim ln As Line = CType(trn.GetObject(objID, OpenMode.ForRead), Line)
  49.                    Dim ls As LineSegment3d = New LineSegment3d(ln.StartPoint, ln.EndPoint)
  50.                    Dim ptArray() As Point3d = ls.IntersectWith(ra3d)
  51.                    If ptArray Is Nothing Then Continue For
  52.                    Dim ptkPrzeciecia As Point3dCollection = New Point3dCollection(ptArray)
  53.                    'SZUKANIE PIERWSZEJ NAJBLIZSZEJ LINII   
  54.                    '   odl=sqrt ((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))
  55.                    odlTmp = Math.Sqrt((prevPt.X - ptkPrzeciecia.Item(0).X) * (prevPt.X - ptkPrzeciecia.Item(0).X) + (prevPt.Y - ptkPrzeciecia.Item(0).Y) * (prevPt.Y - ptkPrzeciecia.Item(0).Y))
  56.                    If odl = 0.0 Then
  57.                        odl = odlTmp
  58.                        nextPt = ptkPrzeciecia.Item(0)
  59.                    ElseIf odl >= odlTmp Then
  60.                        nextPt = ptkPrzeciecia.Item(0)
  61.                    End If
  62.                    lnNajblizsza = ln
  63.                Next
  64.                lnNajblizsza.Highlight()
  65.                Dim promienSledzacy As Ray = New Ray()
  66.                promienSledzacy.BasePoint = ls3d.StartPoint
  67.                promienSledzacy.SecondPoint = ls3d.EndPoint
  68.                promienSledzacy.SetDatabaseDefaults()
  69.                btr.AppendEntity(promienSledzacy)
  70.                trn.AddNewlyCreatedDBObject(promienSledzacy, True)
  71.                trn.Commit()
  72.            Catch ex As Exception
  73.            End Try
  74.            Return lnNajblizsza.ObjectId
  75.        End Using
  76.    End Function
回复

使用道具 举报

15

主题

46

帖子

31

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
75
发表于 2022-7-6 14:01:09 | 显示全部楼层
谢谢你的建议和解决方案
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-5 03:06 , Processed in 0.318205 second(s), 64 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表