Author Topic: passing vectors to a function  (Read 10446 times)

0 Members and 1 Guest are viewing this topic.

Shay Gaghe

  • Newt
  • Posts: 89
Re: passing vectors to a function
« Reply #30 on: July 11, 2014, 01:29:58 AM »
with dims

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: passing vectors to a function
« Reply #31 on: July 11, 2014, 01:41:21 AM »
If you're travelling in space and you are located at 10, 25,13 and you want to travel to Uranus which is at 12,21,15 ; what vector will Sulu need to
use to navigate to your destination?

(distances in parsecs).

i must know the location of Sulu
Sulu is on the bridge .. he is the navigator.
http://en.wikipedia.org/wiki/Hikaru_Sulu


Regarding the piccy you posted,
What is the vector for each of the arms in the left grid .. and in the right grid.?


ie:
What is it's Length, Delta X and Delta Y dimensions ?
< ... piccys >

You still don't understand what constitutes a vector.
What is the Delta X and Delta Y of the arms ??
« Last Edit: July 11, 2014, 01:47:53 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: passing vectors to a function
« Reply #33 on: July 11, 2014, 04:56:09 AM »
Shay Gaghe,
I hate it when I'm forced to have discussions with myself.

Try to answer the questions I asked because the answer you want is in my questions.

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Shay Gaghe

  • Newt
  • Posts: 89
Re: passing vectors to a function
« Reply #34 on: July 11, 2014, 05:15:19 AM »
sorry i didnt see star trek

but let me express my gesture for you

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: passing vectors to a function
« Reply #35 on: July 11, 2014, 06:15:02 AM »
Pretty close :-D:

Try this



Now that we can get to our destination, try to change your code to use the Vector definition (DeltaX, DeltaY, DeltaZ) of each line rather than the endpoints in space.


added: Excellent piccy you made !!
« Last Edit: July 11, 2014, 06:27:55 AM by Kerry »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Shay Gaghe

  • Newt
  • Posts: 89
Re: passing vectors to a function
« Reply #36 on: July 11, 2014, 07:36:20 AM »
Pretty close :-D:

Try this



Now that we can get to our destination, try to change your code to use the Vector definition (DeltaX, DeltaY, DeltaZ) of each line rather than the endpoints in space.


added: Excellent piccy you made !!



in order to get back to where istarted i would inverse the operator to + rather than -

except that i cant go anywhere without knowing the xyz of home

or i didnt understand the task well

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: passing vectors to a function
« Reply #37 on: July 11, 2014, 07:39:34 AM »
Lets say Home is at (-18, 18, 18)

kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Shay Gaghe

  • Newt
  • Posts: 89
Re: passing vectors to a function
« Reply #38 on: July 11, 2014, 07:56:38 AM »
i wanna go home

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: passing vectors to a function
« Reply #39 on: July 11, 2014, 08:05:14 AM »
i wanna go home


Most excellent Navigator Shay.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: passing vectors to a function
« Reply #40 on: July 11, 2014, 08:06:11 AM »
Here's something to read on the trip.

Code - Auto/Visual Lisp: [Select]
  1. ;;
  2. ;;;-------------------------------------------------------------
  3. ;;;-------------------------------------------------------------
  4. ;;; Returns the single unit vector from p1 to p2
  5. (defun kdub:vec2pts (p1 p2)
  6.   (if (not (equal p1 p2 1e-009))
  7.     (mapcar '(lambda (x) (/ x (distance p1 p2))) (mapcar '- p2 p1))
  8.   )
  9. )
  10. ;;
  11. ;;;-------------------------------------------------------------
  12. ;;;-------------------------------------------------------------
  13. ;;
  14. (defun kdub:normal_from_3pts (ip p1 p2 / norm)
  15.   (cond ((inters ip p1 ip p2)
  16.          (foreach p '(p1 p2) (set p (mapcar '- (eval p) ip)))
  17.          (setq norm (list (- (* (cadr p1) (caddr p2)) (* (caddr p1) (cadr p2)))
  18.                           (- (* (caddr p1) (car p2)) (* (car p1) (caddr p2)))
  19.                           (- (* (car p1) (cadr p2)) (* (cadr p1) (car p2)))
  20.                     )
  21.                norm (mapcar '(lambda (x) (* x (/ 1 (distance '(0 0 0) norm)))) norm)
  22.          )
  23.         )
  24.   )
  25. )
  26. ;;
  27. ;;;-------------------------------------------------------------
  28. ;;;-------------------------------------------------------------
  29. ;;
  30. ;;;  Returns the angle (in radians) defined by its summit and two points
  31. ;;; Returned angle is always positive and less than or equal to pi radians.
  32.  
  33. ;; Using vector calculus
  34. (defun kdub:enclosedangle_3pts (ip p1 p2 / v1 v2)
  35.   (if (and (setq v1 (kdub:vec2pts ip p1)) (setq v2 (kdub:vec2pts ip p2)))
  36.     (cond ((equal v1 v2 1e-009) 0.0)
  37.           ((equal v1 (mapcar '- v2) 1e-009) pi)
  38.           (t (* 2 (kdub:asin (/ (distance v1 v2) 2))))
  39.     )
  40.   )
  41. )
  42.  
  43. ;;
  44. ;;;-------------------------------------------------------------
  45. ;;;-------------------------------------------------------------
  46. (defun KDUB:GetEnclosedApexAngle ( apex p1 p2 )
  47.   (- (+ pi pi) (rem (+ pi pi (- (angle apex p1) (angle apex p2))) (+ pi pi)))
  48. )
  49. ;;
  50. ;;;-------------------------------------------------------------
  51. ;;;-------------------------------------------------------------
  52. ;;
  53. (defun KDUB:GetApexAngle<180 ( apex p1 p2 )
  54.   (min (setq a (rem (+ pi pi (- (angle apex p1) (angle apex p2))) (+ pi pi))) (- (+ pi pi) a))
  55. )
  56.  
  57. ;;
  58. ;;;-------------------------------------------------------------
  59. ;;;-------------------------------------------------------------
  60. ;;
  61. ;;; Returns the elevation of point pt from the plane defined by p1 p2 p3
  62.  
  63. (defun kdub:elevabovePlane (pt p1 p2 p3)
  64.   (* (cos
  65.        (kdub:enclosedangle_3pts p1 (mapcar '+ p1 (kdub:normal_from_3pts p1 p2 p3)) pt)
  66.      )
  67.      (distance p1 pt)
  68.   )
  69. )
  70. ;;
  71. ;;;-------------------------------------------------------------
  72. ;;;-------------------------------------------------------------
  73. ;;; Returns the coordinates of the projection of point pt
  74. ;;; on the plane defined by the points p1 p2 p3.
  75.  
  76. (defun kdub:project_pt (pt p1 p2 p3)
  77.   (mapcar '-
  78.           pt
  79.           (mapcar '(lambda (x) (* x (kdub:elevabovePlane pt p1 p2 p3)))
  80.                   (kdub:normal_from_3pts p1 p2 p3)
  81.           )
  82.   )
  83. )
  84. ;;;-------------------------------------------------------------
  85. ;;;-------------------------------------------------------------
  86. ;;
  87. (defun kdub:vec:points->vector (3dPt1 3dPt2) (mapcar '- 3dPt2 3dPt1))
  88. ;;
  89. ;;;-------------------------------------------------------------
  90. ;;;-------------------------------------------------------------
  91. ;;
  92. ;; VXS Multiply a vector by a scalar
  93. ;;
  94. ;; Arguments : a vector and a real
  95. ;;
  96. (defun vxs (v s) (mapcar (function (lambda (x) (* x s))) v))
  97. ;;
  98. ;;;-------------------------------------------------------------
  99. ;;;-------------------------------------------------------------
  100. ;;; -- Function GetPathVector
  101. ;;; Returns the vector at start point from a given object.
  102. ;;; Arguments [Type]:
  103. ;;;   Obj = Object [VLA-OBJECT]
  104. ;;; Return [Type]:
  105. ;;;   > Vector [LIST]
  106. ;;; Notes:
  107. ;;;   None
  108. ;;
  109. (defun kdub:vec:getpathvector (vlaObj)
  110.   (kdub:vec:normalize
  111.   )
  112. )
  113. ;;
  114. ;;;-------------------------------------------------------------
  115. ;;;-------------------------------------------------------------
  116. ;;; -- Function KDUB:VecNormalize
  117. ;;; Normalizes Vec to unit length (1.0).
  118. ;;; Arguments [Type]:
  119. ;;;   Vec = Vector [LIST]
  120. ;;; Return [Type]:
  121. ;;;   > Normalized vector [LIST]
  122. ;;; Notes:
  123. ;;;   None
  124. ;;
  125. (defun kdub:vec:normalize (Vector / Coefficient)
  126.   (setq Coefficient (/ 1.0 (kdub:vec:calculatelength Vector)))
  127.   (kdub:vec:zeroaxisfuzz (mapcar '* Vector (list Coefficient Coefficient Coefficient))
  128.   )
  129. )
  130. ;;
  131. ;;;-------------------------------------------------------------
  132. ;;;-------------------------------------------------------------
  133. ;;
  134. ;;
  135. ;;; -- Function KDUB:eVecLen
  136. ;;; Calculates length of a vector.
  137. ;;; Arguments [Type]:
  138. ;;;   Vec = Vector [LIST]
  139. ;;; Return [Type]:
  140. ;;;   > Length of the vector [REAL]
  141. ;;; Notes:
  142. ;;;   None
  143. ;;
  144. (defun kdub:vec:calculatelength (Vector)
  145.   (car (kdub:vec:zeroaxisfuzz
  146.          (list (sqrt (apply '+ (mapcar '(lambda (a) (* a a)) Vector))))
  147.        )
  148.   )
  149. )
  150. ;;
  151. ;;;-------------------------------------------------------------
  152. ;;;-------------------------------------------------------------
  153. ;;
  154. ;;; Return the cross product, vec1 cross vec2
  155. (defun kdub:vec:crossproduct (vec1 vec2)
  156.   (list (- (* (cadr vec1) (caddr vec2)) (* (caddr vec1) (cadr vec2)))
  157.         (- (* (caddr vec1) (car vec2)) (* (car vec1) (caddr vec2)))
  158.         (- (* (car vec1) (cadr vec2)) (* (cadr vec1) (car vec2)))
  159.   )
  160. )
  161.  
  162.  
  163. ;;
  164. ;;;-------------------------------------------------------------
  165. ;;;-------------------------------------------------------------
  166. ;;
  167. (defun kdub:vec:vla3dpoint->list (vla3dPoint)
  168.   (kdub:vec:zeroaxisfuzz (vlax-safearray->list (vlax-variant-value vla3dPoint)))
  169. )
  170. ;;;------------------------------------------------------------------
  171. ;;;------------------------------------------------------------------
  172. ;;; arcsine (inverse sine) accepts an argument in the range
  173. ;;; -1.0 to 1.0 inclusive, and returns an angle in radians in
  174. ;;; the range -pi/2 to pi/2 inclusive.
  175. (defun kdub:asin (num)
  176.   (cond
  177.     ((> (abs num) 1.0)
  178.      (alert (strcat " Arc-sine error in (KDUB:asin ." "\n Spitting the dummy"))
  179.      (exit)
  180.     )
  181.     ((zerop num) 0.0)
  182.     ((= num 1.0) kglobal:rad90)
  183.     ((= num -1.0) (- kglobal:rad90))
  184.     (t (atan num (sqrt (- 1.0 (* num num)))))
  185.   )
  186. )
  187. ;;;------------------------------------------------------------------
  188. ;;;------------------------------------------------------------------
  189. ;;; arccosine (inverse cosine)
  190. ;;; argument in the range -1.0 to 1.0 inclusive
  191. ;;; returns an angle in radians in the range pi to 0 inclusive
  192. ;;;
  193. (defun kdub:acos (num)
  194.   (if (zerop num)
  195.     (* pi 0.5)
  196.     (atan (sqrt (- 1.0 (* num num))) num)
  197.   )
  198. )
  199. ;;;------------------------------------------------------------------
  200. ;;;------------------------------------------------------------------
  201. ;;;
  202. ;;; (KDUB:defineconstant '*max_Real* 1.797693134862315e+308)
  203. ;; pass num as radian.
  204. (defun kdub:tan (num / cosnum)
  205.   (cond ((zerop (rem num pi)) 0.0)
  206.         ((zerop (rem num (* pi 0.5))) *max_real*)
  207.         ((zerop (setq cosnum (cos num))) *max_real*)
  208.         (t (/ (sin num) cosnum))
  209.   )
  210. )
  211. ;;;------------------------------------------------------------------
  212. ;;;------------------------------------------------------------------
  213. ;;;
  214.  
  215.  
  216.  
  217.  
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: passing vectors to a function
« Reply #41 on: July 11, 2014, 08:14:42 AM »
And these helpers

Code - Auto/Visual Lisp: [Select]
  1. ;;;------------------------------------------------------------------
  2. ;;;------------------------------------------------------------------
  3. ;;;
  4. (defun kdub:protect-assign (symbollist)
  5.   (eval (list 'pragma (list 'quote (list (cons 'protect-assign symbollist)))))
  6. )
  7. ;;;------------------------------------------------------------------
  8. ;;;------------------------------------------------------------------
  9. ;;;
  10. (defun kdub:unprotect-assign (symbollist)
  11.   (eval (list 'pragma (list 'quote (list (cons 'unprotect-assign symbollist)))))
  12. )
  13. ;;;------------------------------------------------------------------
  14. ;;;------------------------------------------------------------------
  15. ;;;
  16. (defun kdub:defineconstant (symbolname symbolvalue)
  17.   (kdub:unprotect-assign (list symbolname))
  18.   (set symbolname symbolvalue)
  19.   (kdub:protect-assign (list symbolname))
  20.   (princ)
  21. )
  22.  
  23. (kdub:defineconstant 'kglobal:pix2 (* pi 2))
  24. (kdub:defineconstant 'kglobal:pi/2 (* pi 0.5))
  25. (kdub:defineconstant 'kglobal:pi/4 (* pi 0.25))
  26. (kdub:defineconstant 'kglobal:pi/8 (* kglobal:pi/4 0.5))
  27.  
  28. (kdub:defineconstant 'kglobal:epsilon 1e-14)
  29. (kdub:defineconstant 'kglobal:max-real 1.797693134862315e+308)
  30.                                              ;double, 64-bit
  31. (kdub:defineconstant 'kglobal:min-real 2.2250738585072014e-308)
  32. (kdub:defineconstant 'kglobal:max-integer 2147483647)
  33.                                              ; signed longint, 32-bit
  34.  
  35. (kdub:defineconstant 'kglobal:rad00 0.00)
  36. (kdub:defineconstant 'kglobal:rad15 (* pi (/ 15 180.0)))
  37. (kdub:defineconstant 'kglobal:rad30 (* pi (/ 30 180.0)))
  38. (kdub:defineconstant 'kglobal:rad45 (* pi 0.25))
  39. (kdub:defineconstant 'kglobal:rad60 (* pi (/ 60 180.0)))
  40. (kdub:defineconstant 'kglobal:rad90 (* pi 0.50))
  41. (kdub:defineconstant 'kglobal:rad135 (* pi 0.75))
  42. (kdub:defineconstant 'kglobal:rad180 pi)
  43. (kdub:defineconstant 'kglobal:rad225 (* pi 1.25))
  44. (kdub:defineconstant 'kglobal:rad270 (* pi 1.50))
  45. (kdub:defineconstant 'kglobal:rad315 (* pi 1.75))
  46. (kdub:defineconstant 'kglobal:rad360 (* pi 2.00))
  47.  
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

JohnK

  • Administrator
  • Seagull
  • Posts: 10626
Re: passing vectors to a function
« Reply #42 on: July 11, 2014, 08:21:42 AM »
Excellent thread Kerry!
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Shay Gaghe

  • Newt
  • Posts: 89
Re: passing vectors to a function
« Reply #43 on: July 11, 2014, 08:25:49 AM »
Thanks
it will be enjoyable trip!    :mrgreen:

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: passing vectors to a function
« Reply #44 on: July 11, 2014, 08:27:35 AM »
Thanks
it will be enjoyable trip!    :mrgreen:

You're welcome. Thanks for playing along.

//------------
Excellent thread Kerry!

Thanks John ... it ended up well, we got home, and no animals were injured.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.