Arrays 如何在列表或数组中保存向量。运动模拟

Arrays 如何在列表或数组中保存向量。运动模拟,arrays,vb.net,list,vector,Arrays,Vb.net,List,Vector,窗口应用程序。这段代码是有一个向量的x,y,z文本框,使点坐标。当我通过按下按钮(在表单中)运行此代码时,它每次都会重写,并且不会保存旧的向量。它只存储当前的x、y、z值。我想知道是否有一种方法可以使用列表或数组将这个向量存储在程序中 Public Property PointCoordinates() As Vector3 Get Dim x As Single = 0, y As Single = 0, z As Single = 0 Single.TryParse(xc

窗口应用程序。这段代码是有一个向量的x,y,z文本框,使点坐标。当我通过按下按钮(在表单中)运行此代码时,它每次都会重写,并且不会保存旧的向量。它只存储当前的x、y、z值。我想知道是否有一种方法可以使用列表或数组将这个向量存储在程序中

  Public Property PointCoordinates() As Vector3
Get
    Dim x As Single = 0, y As Single = 0, z As Single = 0
    Single.TryParse(xcor.Text, x)
    Single.TryParse(ycor.Text, y)
    Single.TryParse(zcor.Text, z)

    Return New Vector3(x, y, z)
End Get
Set(value As Vector3)
    xcor.Text = value.X.ToString()
    ycor.Text = value.Y.ToString()
    zcor.Text = value.Z.ToString()
End Set
结束属性使用常规列表

每次他们点击按钮

Coordinates.Add( PointCoordinates )
您将需要:

Imports System.Collections.Generic

您可以使用通用列表,如下所示:

Dim vectorlist as New List(Of Vector3)   'instantiate a new generic list of type Vector3
Dim vectorvariable as New Vector3(x,y,z) 'instantiate your new Vector3 structure
vectorlist.Add(vectorvariable)           'add the newly created Vector3 structure to your list
要枚举列表,请执行以下操作:

ForEach vectoritem in vectorlist
  MessageBox.Show(String.Format("X: {0}, Y: {1}, Z: {2}",vectoritem.X, vectoritem.Y, vectoritem.Z))
Next


如果我想在这个坐标列表中绘制坐标呢。我应该使用I=1到len(坐标)GL.PointSize(5.0F)GL.Begin(PrimitiveType.Points)GL.Color3(Color.Black)GL.Vertex3(坐标(I))GL.End()下一步我尝试了这个,但没有成功。我遗漏了什么吗?如果我想绘制这个坐标列表呢。我应该使用I=1到len(vectorlist)GL.PointSize(5.0F)GL.Begin(PrimitiveType.Points)GL.Color3(Color.Black)GL.Vertex3(vectorlist(I))GL.End()下一步我尝试了这个,但没有成功。我遗漏了什么吗?我在答案中增加了列举清单的方法。非常感谢。你是最棒的。我知道如何在matlab中进行for循环,但不知道如何在vb中进行。这很有道理
ForEach vectoritem in vectorlist
  MessageBox.Show(String.Format("X: {0}, Y: {1}, Z: {2}",vectoritem.X, vectoritem.Y, vectoritem.Z))
Next
For i As Integer = 0 to vectorlist.Count-1
  MessageBox.Show(String.Format("X: {0}, Y: {1}, Z: {2}",vectorlist(i).X, vectorlist(i).Y, vectorlist(i).Z))
Next