Author Topic: points 3dmatrix  (Read 1625 times)

0 Members and 1 Guest are viewing this topic.

dgpuertas

  • Newt
  • Posts: 81
points 3dmatrix
« on: November 19, 2012, 03:59:23 AM »

I have a problem of geometry. I need the coordenates of any 3D points that:

- The points its in the plane normal of two points P1 P2, and its in a circle with center in P1 and radius R
- There are N points regularly spaced in the circunference.



(defun 3dmatrixpoints (pto1 pto2 raduis n)
  ....

)

Thanks a lot and sorry about my english

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: points 3dmatrix
« Reply #1 on: November 19, 2012, 04:47:04 AM »
Look into the trans function. What you're after is basically a UCS with its origin at P1 and its Z axis going through P2 ... the trans function works on a normal as well ... you need not make a true UCS.
 
Then you can use the polar function to obtain the Nx points around the center.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: points 3dmatrix
« Reply #2 on: November 19, 2012, 05:40:13 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun test (p1 p2 n r / A A0 V)
  2.   (setq v  (distance p1 p2)
  3.         v  (mapcar (function /) (mapcar (function -) p2 p1) (list v v v))
  4.         a  (/ pi n 0.5)
  5.         a0 0.
  6.         p0 (trans p1 0 v)
  7.   )
  8.   (repeat n
  9.     (entmakex (list '(0 . "point") (cons 10 (trans (polar p0 a0 r) v 0))))
  10.     (setq a0 (+ a a0))
  11.   )
  12.     (list '(0 . "circle") (cons 10 (trans p1 '(0. 0. 1.) v)) (cons 40 r) (cons 210 v))
  13.   )
  14.   (entmakex (list '(0 . "line") (cons 10 p1) (cons 11 p2)))
  15.   (princ)
  16. )
  17. (test '(5. 6. 1.)'(6. 7. 8.) 7 2.1)
« Last Edit: November 19, 2012, 06:08:48 AM by ElpanovEvgeniy »

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: points 3dmatrix
« Reply #3 on: November 19, 2012, 06:03:41 AM »
My version which only calculates the XYZ values of each point:
Code - Auto/Visual Lisp: [Select]
  1. (defun 2Pt->3dVector (Pt1 Pt2) (mapcar '- Pt2 Pt1))
  2.  
  3. (defun DivideCirc (Radius Num / lst ang dang)
  4.   (setq ang (* pi 2.0)
  5.  dang (/ ang Num))
  6.   (repeat Num (setq lst (cons (polar '(0.0 0.0 0.0) (setq ang (- ang dang)) Radius) lst)))
  7.   lst)
  8.  
  9. (defun MovePt (Pt Vect) (mapcar '+ Pt Vect))
  10.  
  11. (defun DivideCircTrans (Pt1 Pt2 Radius Num / vect)
  12.   (setq vect (2Pt->3dVector Pt1 Pt2))
  13.   (mapcar '(lambda (Pt) (MovePt (trans Pt vect 0) Pt1)) (DivideCirc Radius Num)))
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

dgpuertas

  • Newt
  • Posts: 81
Re: points 3dmatrix
« Reply #4 on: November 19, 2012, 06:15:34 AM »
Thanks a lot,
irneb and elpanovEvgeniy

my version:
Code: [Select]
(defun 3d_matrixpoints (pto1 pto2 radio n / v p0)

  (setq v (nrm_vec (mapcar (function -) pto2 pto1))
p0 (trans pto1 0 v))

(mapcar (function (lambda (an) (trans (polar p0 an radio) v 0))) (cdr (rseq 0. 2pi (1+ n))))
)

With two subfunctions

nrm_vec -> normalize vector
and
rseq, sequence of real numbers for 0 to 2pi (2pi its a global variable with 6,28....)

Thanks

dgpuertas

  • Newt
  • Posts: 81
Re: points 3dmatrix
« Reply #5 on: November 19, 2012, 06:26:40 AM »
without normalize vector works too.

Code - Auto/Visual Lisp: [Select]
  1. (defun 3d_matrixpoints (pto1 pto2 radio n / v p0)
  2.   (setq v (mapcar (function -) pto2 pto1)
  3.         p0 (trans pto1 0 v))
  4.  
  5. (mapcar (function (lambda (an) (trans (polar p0 an radio) v 0))) (cdr (rseq 0. 2pi (1+ n))))
  6. )
  7. (defun rseq (start endp n / lst d)
  8.   (cond
  9.     ((= n 1) (list start))
  10.     ((< n 1) nil)
  11.     ((< endp start) (reverse (rseq endp start n)))
  12.     (T
  13.      (setq d (/ (float (- endp start)) (1- n)))
  14.      (repeat n
  15.        (setq lst (cons (+ start (* (setq n (1- n)) d)) lst))))))
  16.  


ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: points 3dmatrix
« Reply #6 on: November 19, 2012, 06:37:44 AM »
we hid work with matrices for the function of trans.
If you handle them yourself matrix, necessarily lead to the unit vector of length!

otherwise, there is an error in the calculations...

Lee Mac

  • Seagull
  • Posts: 12929
  • London, England
Re: points 3dmatrix
« Reply #7 on: November 19, 2012, 08:17:32 AM »
For fun, without using trans:

Code - Auto/Visual Lisp: [Select]
  1. (defun cpoints ( p q n r / a i m )
  2.     (setq m (LM:ocsframe (vx1 (mapcar '- q p)))
  3.           p (mxv m p)
  4.           m (trp m)
  5.           i (/ pi n 0.5)
  6.           a 0.0
  7.     )
  8.     (repeat n
  9.         (entmake (list '(0 . "POINT") (cons 10 (mxv m (polar p a r)))))
  10.         (setq a (+ a i))
  11.     )
  12.     (princ)
  13. )
  14.  
  15. ;; OCS Frame - Lee Mac
  16. ;; Uses the Arbitrary Axis Algorithm to define
  17. ;; a coordinate frame, given a WCS Unit Normal
  18.  
  19. (defun LM:OCSFrame ( z / v x )
  20.     (if (and
  21.             (< (abs (car  z)) 0.015625)
  22.             (< (abs (cadr z)) 0.015625)
  23.         )
  24.         (setq v '(0.0 1.0 0.0))
  25.         (setq v '(0.0 0.0 1.0))
  26.     )
  27.     (setq x (vx1 (v^v v z)))
  28.     (list x (vx1 (v^v z x)) z)
  29. )
  30.  
  31. ;; Matrix Transpose  -  Doug Wilson
  32. ;; Args: m - nxn matrix
  33.  
  34. (defun trp ( m )
  35.     (apply 'mapcar (cons 'list m))
  36. )
  37.  
  38. ;; Matrix x Vector  -  Vladimir Nesterovsky
  39. ;; Args: m - nxn matrix, v - vector in R^n
  40.  
  41. (defun mxv ( m v )
  42.     (mapcar '(lambda ( r ) (apply '+ (mapcar '* r v))) m)
  43. )
  44.  
  45. ;; Unit Vector  -  Lee Mac
  46. ;; Args: v - vector in R^2 or R^3
  47.  
  48. (defun vx1 ( v )
  49.     (   (lambda ( n ) (if (equal 0.0 n 1e-10) nil (mapcar '/ v (list n n n))))
  50.         (distance '(0.0 0.0 0.0) v)
  51.     )
  52. )
  53.  
  54. ;; Vector Cross Product  -  Lee Mac
  55. ;; Args: u,v - vectors in R^3
  56.  
  57. (defun v^v ( u v )
  58.     (list
  59.         (- (* (cadr u) (caddr v)) (* (cadr v) (caddr u)))
  60.         (- (* (car  v) (caddr u)) (* (car  u) (caddr v)))
  61.         (- (* (car  u) (cadr  v)) (* (car  v) (cadr  u)))
  62.     )
  63. )