2013-09-25 63 views
0

我目前正試圖在vb.net上編寫一個3D圖形引擎(yaay ...),但是使用它來做數學的向量(向量)真的很尷尬,以至於有很多觀點使用它有什麼建議嗎?有沒有簡單的方法在vb中使用矢量?

+0

你可以添加你所使用的代碼的例子嗎? – Sean

+0

是的,當然,我將不得不在現在後發佈我無法訪問我的家用電腦。 – Enderbro

+0

好的,在編輯完成後留下另一條評論,我會收到通知回來看看。 – Sean

回答

-2
Friend Module Func 
     ''' <summary> 
     ''' Program Function 
     ''' </summary> 
     ''' <remarks></remarks> 
#Region "Vector3" 
     Public va, vb, vc, vd As Single 
     Public VectorDot1, VectorDot2 As Double 
     Public vectorAngle As Single 
     Function CalculateVector(ByVal point1 As Drawing.Point, ByVal point2 As Drawing.Point) As Double 
      Dim v As Single = 0 
      va = point2.X - point1.X 
      vb = point2.X - point1.Y 
      vc = point2.X - point1.X 
      vd = point2.Y - point1.Y 
      v = point2.X - point1.X + point2.Y - point1.Y 
      Return v 
     End Function 

     Function CaluclateDotProduct(ByVal pointv1 As Drawing.Point, ByVal pointv2 As Drawing.Point, ByVal pointv3 As Drawing.Point, ByVal pointv4 As Drawing.Point) As Double 
      Dim v1, v2 As Double 
      v1 = CalculateVector(pointv1, pointv2) 
      v2 = CalculateVector(pointv3, pointv4) 

      v1 = va * vb + vc * vd 

      v2 = va * vb + vc * vd 

      VectorDot1 = v1 
      VectorDot2 = v2 

      Return v1 And v2 

     End Function 

     Function VectorCrossProduct(ByVal point1 As Drawing.Point, ByVal point2 As Drawing.Point) As Double 
      Dim v1 As Double = CalculateVector(point1, point2) 

      Dim v2 As Double = CalculateVector(point1, point2) 



      Return va * vd - vb * vc 
     End Function 
     Function ATan2(ByVal opp As Single, ByVal adj As _ 
    Single) As Single 

     End Function 
     Function Vector_Angle(ByVal pointv1 As Drawing.Point, ByVal pointv2 As Drawing.Point, ByVal pointv3 As Drawing.Point, ByVal pointv4 As Drawing.Point) As Double 
      Dim dotproduct As Double = CaluclateDotProduct(pointv1, pointv2, pointv3, pointv4) 
      Dim crossproduct As Double = VectorCrossProduct(pointv1, pointv2) 
      vectorAngle = Math.Atan2(crossproduct, dotproduct) 

      Return vectorAngle 
     End Function 
#End Region 


    End Module 

    Public Class Vector3 
    Dim id As Integer 
    Dim name As String 
    Dim _x, _y As Single 
    Dim result As Double 
    Dim _length As Double 
    Dim _vector As Double 
    Dim _dotProduct As Double 
    Dim _crossProduct As Double 
    Dim _angle As Double 
    Public ReadOnly Property CrossProduct() As Double 
     Get 
      Return _dotProduct 
     End Get 
    End Property 
    Public ReadOnly Property DotProduct() As Double 
     Get 
      Return _dotProduct 
     End Get 
    End Property 
    Public ReadOnly Property Vector() As Double 
     Get 
      Return _vector 
     End Get 
    End Property 
    Public ReadOnly Property Length() As Double 
     Get 
      Return Core.vectorAngle 
     End Get 
    End Property 
    Public WriteOnly Property X() As Single 
     Set(ByVal value As Single) 
      Core.va = value 
     End Set 
    End Property 
    Public WriteOnly Property Y() As Single 

     Set(ByVal value As Single) 
      Core.vb = value 
     End Set 
    End Property 
    Public Property _Angle_() As Double 
     Get 
      Return Me._angle 
     End Get 
     Set(ByVal value As Double) 
      Me._angle = value 
     End Set 
    End Property 
    Sub New(ByVal id As Integer, ByVal name As String, ByVal point1 As Drawing.Point, ByVal point2 As Drawing.Point) 
     Me.id = id 
     Me.name = name 
     _vector = Core.CalculateVector(point1, point2) 
    End Sub 
    Public Sub VectorCalculate(ByVal point As Point, ByVal point2 As Point) 
     Core.CalculateVector(point, point2) 
    End Sub 
    Public Sub CalculateVectorLength(ByVal point1 As Drawing.Point, ByVal point2 As Drawing.Point) 
     _length = Core.CalculateVector(point1, point2) 
    End Sub 

    Public Sub Dot_Product(ByVal pointv1 As Drawing.Point, ByVal pointv2 As Drawing.Point, ByVal pointv3 As Drawing.Point, ByVal pointv4 As Drawing.Point) 
     _dotProduct = Core.CaluclateDotProduct(pointv1, pointv2, pointv3, pointv4) 

    End Sub 

    Public Sub Cross_Product(ByVal point1 As Drawing.Point, ByVal point2 As Drawing.Point) 
     _crossProduct = Core.VectorCrossProduct(point1, point2) 
    End Sub 

    Public Sub Angle(ByVal pointv1 As Drawing.Point, ByVal pointv2 As Drawing.Point, ByVal pointv3 As Drawing.Point, ByVal pointv4 As Drawing.Point) 
     _angle = Core.Vector_Angle(pointv1, pointv2, pointv3, pointv4) 

    End Sub 
相關問題