乐筑天下

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

寻找三维向量的方位角

[复制链接]

4

主题

26

帖子

1

银币

初来乍到

Rank: 1

铜币
42
发表于 2005-8-15 13:31:11 | 显示全部楼层 |阅读模式
大家好,我有一个小问题,除了一个小部分,基本上解决了
我在3D中定义了一条线。我想确定这条线相对于线的起点在由法线(0,0,1)和点(0,零,0)定义的平面中的方位角。该平面是xy平面。方位角将从xy平面中的矢量(0,1,0)测量
以下是获取角度的方法
  1. N is the normal of the plane (0,0,1)
  2. P is the line that I am working with. It has coordinates Psx,Psy,Psz and Pex,Pey,Pez. where Ps refers to the starting point and Pe refers to the end point.
  3. V is a vector in the direction of P. Vx = Pex-Psx;Vy = Pey-Psy;Vz = Pez-Psz
  4. Now, project V onto the xy plane:
  5. U = V - (V.N)*N; where V.N is the dot product
  6. Now we have a vector in the xy plane, we can find the angle of the this vector and the vector M (0,1,0) which defines North.
  7. To determine the angle:
  8. theta = arccos(U.M/(|U|*|M|))

我遇到的问题是,θ将是两个向量之间的锐角。换句话说,如果我有一条270度的直线,计算结果将返回90度。

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

4

主题

26

帖子

1

银币

初来乍到

Rank: 1

铜币
42
发表于 2005-8-15 14:20:15 | 显示全部楼层
我想我需要取相关向量的行列式,以找出角度的测量方式
  1. N = 0,0,1; this is the direction of the normal describing the xy plane
  2. M = 0,1,0; This vector defines north
  3. U = Ux,Uy,Uz; this is the vector that I want to find the angle of relative to M
  4. For an example, lets say U = -1,1,0; this would put the vector in the 2nd quadrant and it should have an angle of 315 degrees. If I use the procedure in my last post I get an angle of 45 degrees.
  5. Now if I find the determinant of:
  6. |-1 1 0|
  7. | 0 1 0|  = -1
  8. | 0 0 1|
  9. I believe, according to the sign that the angle has been calculated the wrong way. So If I take 360 and subtract 45 I arrive at 315 degrees. Which is what I want.
  10. Say I used U=2,2,0 which is 45 degrees, I would get
  11. | 2 2 0|
  12. | 0 1 0|  = 2
  13. | 0 0 1|
  14. The positive result would indicate that I do not need a correction.
  15. If the result is 0, it means that the vectors are parallel.

我找遍了所有地方,似乎找不到答案(或者至少我能理解)。我相信对3个向量进行确定并检查结果的符号是正确的方法。我已经对一些案例的结果进行了测试,在每种情况下似乎都有效。我没有改变我工作的平面或北向量的方向
有人能帮我核实一下吗?或者我做的事情有误吗?
回复

使用道具 举报

3

主题

70

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
100
发表于 2005-8-15 14:57:09 | 显示全部楼层
这样如何:
将北方位角定义为从正北顺时针测量的度数,计算直线的Δx和Δy。忘记三角洲z。将xy网格的原点置于线的起点,然后查看线所在的象限。根据哪个象限,即应用不同的规则来计算方位角:
象限一:
方位角=弧坦(δx/δy)
第二象限:
感谢您的回复 cad-waulader.
感谢您的方法。在计算地下钻孔角度时,我使用了类似的方法,并且效果很好(但是我更喜欢您的方法)。
我可能会使用您的方法,但我仍然想知道我是否在上一篇文章中就行列式外出吃午饭?
回复

使用道具 举报

3

主题

70

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
100
发表于 2005-8-15 15:08:55 | 显示全部楼层
必须查阅那方面的书籍...矢量计算保存在我大脑生锈/尘土飞扬的一侧。
回复

使用道具 举报

0

主题

1

帖子

1

银币

初来乍到

Rank: 1

铜币
1
发表于 2005-8-15 15:17:34 | 显示全部楼层

告诉我,我应该在学校更加注意。我从未想过我会如此广泛地与他们一起工作。
从我目前正在阅读的一些文本中,我在之前的帖子中所做的决定因素是平行六面体的签名卷。签名卷意味着它指示扫描的方向。我相信这可以告诉我角度的计算方式。我已经做了不少测试,它们似乎证实了我的怀疑。
无论如何,我可能会为autocad模拟一些vba来确认我的计算。如果有人感兴趣,我明天某个时候会发布我的结果以及宏。
回复

使用道具 举报

4

主题

26

帖子

1

银币

初来乍到

Rank: 1

铜币
42
发表于 2005-8-15 15:28:15 | 显示全部楼层
如果有人感兴趣,这里是我想出的代码。它是用 VBA for AutoCAD 编写的。它似乎像我预期的那样工作。只需将其复制并粘贴到空模块中即可。
  1. Option Explicit
  2. Private Const x As Integer = 0
  3. Private Const y As Integer = 1
  4. Private Const z As Integer = 2
  5. Private Const PI As Double = 3.14159
  6. Public Sub findAzimuth()
  7. Dim pickedEntity As AcadEntity
  8. Dim pickedPoint As Variant
  9. Dim myLine As AcadLine
  10. ThisDrawing.Utility.GetEntity pickedEntity, pickedPoint, "Please select a line: " & vbCr
  11. If pickedEntity Is Nothing Then Exit Sub
  12. If TypeOf pickedEntity Is AcadLine Then
  13.     Set myLine = pickedEntity
  14. Else
  15.     ThisDrawing.Utility.Prompt vbCrLf & "Be sure to select a line next time!" & vbCr
  16.     Exit Sub
  17. End If
  18. Dim N(2) As Double 'the normal of the plane
  19. Dim M(2) As Double 'the direction of the azimuth line
  20. Dim v(2) As Double 'the vector representing the line
  21. Dim U(2) As Double 'the projection of V onto the plane
  22. N(x) = 0
  23. N(y) = 0
  24. N(z) = 1
  25. M(x) = 0
  26. M(y) = 1
  27. M(z) = 0
  28. v(x) = myLine.EndPoint(x) - myLine.StartPoint(x)
  29. v(y) = myLine.EndPoint(y) - myLine.StartPoint(y)
  30. v(z) = myLine.EndPoint(z) - myLine.StartPoint(z)
  31. Dim dpResult As Double 'dot product result
  32. dpResult = dotProduct(v, N)
  33. U(x) = v(x) - dpResult * N(x)
  34. U(y) = v(y) - dpResult * N(y)
  35. U(z) = v(z) - dpResult * N(z)
  36. Dim theta As Double
  37. Dim dpVectorNormal As Double
  38. Dim vectMagnitude As Double
  39. vectMagnitude = (vectorMagnitude(U) * vectorMagnitude(M)) 'pre-calculate this value - if it is zero, are angle calculation is greatly simplified
  40. If vectMagnitude > 0 Then
  41.     dpVectorNormal = dotProduct(U, M) 'calculate the dot product of the projected vector and the azimuth vector
  42.    
  43.     theta = aCos(dpVectorNormal / vectMagnitude)
  44.    
  45.     'now we need to figure out which way the angle was measured from
  46.     Dim D As Double
  47.     D = determinant(U, M, N)
  48.    
  49.     If D < 0 Then
  50.         theta = 2 * PI - theta
  51.     End If
  52. Else
  53.     'the hole looks vertical in that plane
  54.     theta = 0
  55. End If
  56. 'convert the angle to degrees
  57. theta = theta * 180 / PI
  58. ThisDrawing.Utility.Prompt vbCr & "The Azimuth is: " & theta
  59. Set myLine = Nothing
  60. Set pickedEntity = Nothing
  61. End Sub
  62. Private Function determinant(v1 As Variant, v2 As Variant, v3 As Variant) As Double
  63. 'this will calculate the 3x3 determinant of the passed vectors
  64. 'v1(x),v1(y),v1(z)
  65. 'v2(x),v2(y),v2(z)
  66. 'v3(x),v3(y),v3(z)
  67. Dim a As Double
  68. Dim b As Double
  69. Dim c As Double
  70. a = v1(x) * (v2(y) * v3(z) - v2(z) * v3(y))
  71. b = v1(y) * (v2(x) * v3(z) - v2(z) * v3(x))
  72. c = v1(z) * (v2(x) * v3(y) - v2(y) * v3(x))
  73. determinant = a - b + c
  74. End Function
  75. Private Function aCos(v As Double) As Double
  76. aCos = Atn(-v / Sqr(-v * v + 1)) + 2 * Atn(1)
  77. End Function
  78. Private Function vectorMagnitude(v As Variant) As Double
  79.     vectorMagnitude = v(x) * v(x) + v(y) * v(y) + v(z) * v(z)
  80.     vectorMagnitude = Sqr(vectorMagnitude)
  81. End Function
  82. Private Function dotProduct(v1 As Variant, v2 As Variant) As Double
  83. dotProduct = v1(0) * v2(0) + v1(1) * v2(1) + v1(2) * v2(2)
  84. End Function

回复

使用道具 举报

4

主题

26

帖子

1

银币

初来乍到

Rank: 1

铜币
42
发表于 2005-8-16 08:51:33 | 显示全部楼层
看起来棒极了!我一点头绪都没有.......但是看起来很棒!:dood:
回复

使用道具 举报

4

主题

26

帖子

1

银币

初来乍到

Rank: 1

铜币
42
发表于 2005-8-16 09:36:49 | 显示全部楼层

如果您在autocad中运行它,它会要求您选择一条线。然后它会告诉您该线的方位角。它假设您想要该线的方位角,就好像它被投影到xy平面(平面图)一样,并且它假设正y轴是北。
可以进行许多优化以使其更快,但我没有进行优化,因为它可能会模糊一些数学工作原理。
回复

使用道具 举报

4

主题

26

帖子

1

银币

初来乍到

Rank: 1

铜币
42
发表于 2005-8-16 09:54:58 | 显示全部楼层
谢谢特洛伊.........我是一个机械类型的人,从来没有理由需要一个方位角......以为它像阿斯玛一样是总和......
好吧......不好笑......
回复

使用道具 举报

3

主题

70

帖子

3

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
100
发表于 2005-8-16 11:17:55 | 显示全部楼层
特洛伊,对我来说看起来还不错
斯威夫特
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-10 21:07 , Processed in 0.441037 second(s), 72 queries .

© 2020-2025 乐筑天下

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