Some code for handling coordinates and vectors in VB.Net. Coded in v2003. You need to import System.Math for the code to work.
Last updates: 21 April 2006
Current contents:
Coordinate Systems: Cartesian, Spherical Polar and Cylindrical Polar. Each can be defined with offsets and rotations relative to the global cartesian coordinate system.
Coordinate Transforms: From one local type to another, from any defined system to any other defined system, cartesian rotations (global and local).
Vectors: Addition, subtraction, translation, scaling, dot product, cross product.
Solids: Coordinate generation on the surface of spheres, ellipsoids, cuboids and cylinders.
Usage:
VB Code:
Dim Global As New CoordinateSystem.Cartesian() Dim mycartsystem As New CoordinateSystem.Cartesian(10, 10, 0, 0, 0, 0, 1) Dim mycartcoord As New Coordinate.Cartesian(mycartsystem, 1, 0, 0) Dim mycartcoord2 As New Coordinate.Cartesian(mycartsystem, 0, 1, 0) Dim mycartcoordorigin As New Coordinate.Cartesian(mycartsystem, 0, 0, 0) Dim myvector1 As New Vector.Cartesian myvector1.StartPoint = mycartcoordorigin myvector1.EndPoint = mycartcoord Dim myvector2 As New Vector.Cartesian myvector2.StartPoint = mycartcoordorigin myvector2.EndPoint = mycartcoord2 Dim subvector As New Vector.Cartesian subvector = Operations.VectorOps.Subtract(myvector1, myvector2) MsgBox(subvector.X2 & ", " & subvector.Y2 & ", " & subvector.Z2)
The above code does the following:
-Creates a new cartesian coordinate system located at (10,10,0) with respect to the global, but with parallel axes.
-Generates three new coordinates within this system, (0,0,0), (1,0,0) and (0,1,0).
-Defines two new vectors within the system, one running along the x-axis and one along the y-axis.
-Defines a new vector by subtracting the y-axis vector from the x-axis vector. The new vector runs from (0,0,0) to (1,-1,0).
-Returns the endpoint of the new vector.
The picture illustrates how the offset and rotation properties are used: offsets are cartesian with respect to a global system centred at (0,0,0). The Theta rotation direction rotates the x axis onto the y axis, the Phi direction rotates the x axis onto the z axis and the Psi rotation angle rotates the y axis onto the z axis.
The same applies to the theta and phi coordinates in spherical and cylindrical polar coordinates.
There will be further additions to this code as necessary.
zaza


Reply With Quote