有没有一种简单的方法在vb中使用向量?

时间:2013-09-25 11:28:29

标签: vb.net

我目前正在尝试在vb.net上编写一个3D图形引擎(yaay ...),但我使用它做的数学(向量)真的很难用很多点任何建议吗?

2 个答案:

答案 0 :(得分:2)

答案 1 :(得分:-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
相关问题