## ProblemYou want to work with three-dimensional coordinates as single entities. ## SolutionSample code folder: Chapter 06\ThreePoint Create a ## DiscussionThe following class definition is similar to the Public Class Point3D Public X As Double Public Y As Double Public Z As Double Public Sub New(ByVal xPoint As Double, _ ByVal yPoint As Double, ByVal zPoint As Double) Me.X = xPoint Me.Y = yPoint Me.Z = zPoint End Sub Public Overrides Function Tostring() As String Return "{X=" & X & ",Y=" & Y & ",Z=" & Z & "}" End Function End Class The most important modification is the addition of a public The following code demonstrates the use of some Dim result As New System.Text.StringBuilder Dim distance As Double Dim point1 As Point3D Dim point2 As Point3D Dim deltaX As Double Dim deltaY As Double Dim deltaZ As Double point1 = New Point3D(3, 4, 5) point2 = New Point3D(7, 2, 3) deltaX = point1.X - point2.X deltaY = point1.Y - point2.Y deltaZ = point1.Z - point2.Z distance = Math.Sqrt(deltaX ^ 2 + deltaY ^ 2 + deltaZ ^ 2) result.AppendLine("3D Point 1: " & point1.ToString()) result.AppendLine("3D Point 2: " & point2.ToString()) result.AppendLine("Distance: " & distance.ToString()) MsgBox(result.ToString()) Figure 6-14 shows the results of calculating the distance in space between these two coordinates. ## Figure 6-14. Manipulating three-dimensional coordinates with a Point3D class## See AlsoSearch for "basic 3D math" on the Web for a variety of explanations and further information about this subject. |

Visual Basic 2005 Cookbook: Solutions for VB 2005 Programmers (Cookbooks (OReilly))

ISBN: 0596101775

EAN: 2147483647

EAN: 2147483647

Year: 2006

Pages: 400

Pages: 400

Authors: Tim Patrick, John Craig

Similar book on Amazon

flylib.com © 2008-2017.

If you may any questions please contact us: flylib@qtcs.net

If you may any questions please contact us: flylib@qtcs.net