Guest User

Untitled

a guest
Aug 20th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function dotProduct(v1 as vector2, v2 as vector2) as double
  2.     dim as coord2_d a, b 'To hold our converted vectors
  3.     dim as double dot
  4.    
  5.     'Convert everything to double depending on base vector type
  6.    
  7.     select case v1.dataType
  8.     case vector_Int:
  9.         a.x = v1.i.x
  10.         a.y = v1.i.y
  11.     case vector_Dbl:
  12.         a.x = v1.d.x
  13.         a.y = v1.d.y
  14.     case vector_Rad:
  15.         a.x = cos(v1.r.o)*v1.r.r
  16.         a.y = sin(v1.r.o)*v1.r.r
  17.     case else 'assume double
  18.         a.x = v1.d.x
  19.         a.y = v1.d.y
  20.     end select
  21.    
  22.     'same for 2nd input vector
  23.    
  24.     select case v2.dataType
  25.     case vector_Int:
  26.         b.x = v2.i.x
  27.         b.y = v2.i.y
  28.     case vector_Dbl:
  29.         b.x = v2.d.x
  30.         b.y = v2.d.y
  31.     case vector_Rad:
  32.         b.x = cos(v2.r.o)*v2.r.r
  33.         b.y = sin(v2.r.o)*v2.r.r
  34.     case else 'assume double
  35.         b.x = v2.d.x
  36.         b.y = v2.d.y
  37.     end select
  38.    
  39.     dot = a.x*b.x + a.y*b.y
  40.     return dot
  41. end function
  42.  
  43. function dotProduct(v1 as vector3, v2 as vector3) as double
  44.     dim as coord3_d a, b 'To hold our converted vectors
  45.     dim as double dot
  46.    
  47.     'Convert everything to double depending on base vector type
  48.    
  49.     select case v1.dataType
  50.     case vector_Int:
  51.         a.x = v1.i.x
  52.         a.y = v1.i.y
  53.         a.z = v1.i.z
  54.     case vector_Dbl:
  55.         a.x = v1.d.x
  56.         a.y = v1.d.y
  57.         a.z = v1.d.z
  58.     case vector_Sph:
  59.         a.x = cos(v1.s.o)*v1.s.r*sin(v1.s.p)
  60.         a.y = sin(v1.s.o)*v1.s.r*sin(v1.s.p)
  61.         a.z = cos(v1.s.p)*v1.s.r
  62.     case vector_Cyl:
  63.         a.x = cos(v1.c.o)*v1.c.r
  64.         a.y = sin(v1.c.o)*v1.c.r
  65.         a.z = v1.c.z
  66.     case else 'assume double
  67.         a.x = v1.d.x
  68.         a.y = v1.d.y
  69.         a.z = v1.d.z
  70.     end select
  71.    
  72.     select case v2.dataType
  73.     case vector_Int:
  74.         b.x = v2.i.x
  75.         b.y = v2.i.y
  76.         b.z = v2.i.z
  77.     case vector_Dbl:
  78.         b.x = v2.d.x
  79.         b.y = v2.d.y
  80.         b.z = v2.d.z
  81.     case vector_Sph:
  82.         b.x = cos(v2.s.o)*v2.s.r*sin(v2.s.p)
  83.         b.y = sin(v2.s.o)*v2.s.r*sin(v2.s.p)
  84.         b.z = cos(v2.s.p)*v2.s.r
  85.     case vector_Cyl:
  86.         b.x = cos(v2.c.o)*v2.c.r
  87.         b.y = sin(v2.c.o)*v2.c.r
  88.         b.z = v2.c.z
  89.     case else 'assume double
  90.         b.x = v2.d.x
  91.         b.y = v2.d.y
  92.         b.z = v2.d.z
  93.     end select
  94.    
  95.     'same for 2nd input vector
  96.    
  97.    
  98.     dot = a.x*b.x + a.y*b.y + a.z*b.z
  99.     return dot
  100. end function
Add Comment
Please, Sign In to add comment