Results 1 to 10 of 10

Thread: Coordinates, Vectors and 3D volumes

Threaded View

  1. #1

    Thread Starter
    Frenzied Member zaza's Avatar
    Join Date
    Apr 2001
    Location
    Borneo Rainforest Habits: Scratching
    Posts
    1,486

    Coordinates, Vectors and 3D volumes

    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:
    1. Dim Global As New CoordinateSystem.Cartesian()
    2.  
    3.         Dim mycartsystem As New CoordinateSystem.Cartesian(10, 10, 0, 0, 0, 0, 1)
    4.  
    5.         Dim mycartcoord As New Coordinate.Cartesian(mycartsystem, 1, 0, 0)
    6.  
    7.         Dim mycartcoord2 As New Coordinate.Cartesian(mycartsystem, 0, 1, 0)
    8.        
    9.         Dim mycartcoordorigin As New Coordinate.Cartesian(mycartsystem, 0, 0, 0)
    10.  
    11.         Dim myvector1 As New Vector.Cartesian
    12.         myvector1.StartPoint = mycartcoordorigin
    13.         myvector1.EndPoint = mycartcoord
    14.  
    15.         Dim myvector2 As New Vector.Cartesian
    16.         myvector2.StartPoint = mycartcoordorigin
    17.         myvector2.EndPoint = mycartcoord2
    18.  
    19.         Dim subvector As New Vector.Cartesian
    20.  
    21.         subvector = Operations.VectorOps.Subtract(myvector1, myvector2)
    22.  
    23.         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
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by zaza; Apr 21st, 2006 at 04:56 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width