我有以下代码:
我试图将射线射向飞机,而我唯一的信息是: 飞机 - 3点(10,0,0),(10,10,0),(20,10,0)和 雷 - 1点(10,0,5)。
在图像中,已知的信息是绿点,即3点。我有第一个红点,Ray与绿线平行拍摄。我试图找到第二个红点。哪个是平面@第二个绿点的交点。
我试图使用平面点来改变方向,以了解飞机的新方向是什么。
我们将非常感谢您对代码的任何帮助。它正在努力获取线的长度,但是Ray的新坐标在交点处不起作用。
'矢量数学
Dim v1 As Vector3D = New Vector3D(10, 0, 0)
Dim v2 As Vector3D = New Vector3D(10, 10, 0)
Dim N1 As Vector3D = v2 - v1
N1.Normalize()
Dim v3 As Vector3D = New Vector3D(20,10,0)
Dim N2 As Vector3D = v2 + v3
N2.Normalize()
'New Ray to Intersect with Plane
Dim vPipe As New Vector3D(10, 0, 5)
Dim vPipe1 As New Vector3D
vPipe1 = intersectPlane(N2, v2, vPipe, N1)
Dim vPipeEnd As New Vector3D
vPipeEnd = vPipe + vPipe1
'Create new Shape in Helix
Dim vPipe3D As ExtrudedVisual3D = XamlReader.Parse(XamlWriter.Save(hlx_Volume))
With vPipe3D
.Path.Clear()
.Path.Add(New Media3D.Point3D(vPipe.X, vPipe.Y, vPipe.Z))
.Path.Add(New Media3D.Point3D(vPipeEnd.X, vPipeEnd.Y, vPipeEnd.Z))
.Section.Clear()
.Section.Add(New Point(0, 0))
.Section.Add(New Point(0, 50))
.Section.Add(New Point(50, 50))
.Section.Add(New Point(50, 0))
End With
用于返回Point / Vector(Ray)与Point / Vector(Plane)的交集的函数。
函数intersectPlane(n为Vector3D,p0为Vector3D,l0为Vector3D,l为Vector3D)为Vector3D
Dim t As Single
'Assuming vectors are all normalized
Dim denom As Single = Vector3D.DotProduct(n, l)
If denom > 0.000001 Then
Dim p010 = p0 - l0
t = Vector3D.DotProduct(p010, n) / denom
Return p010
End If
End Function