Author Topic: ? create UCS at 'double' angle to WCS via AutoLISP  (Read 1055 times)

0 Members and 1 Guest are viewing this topic.

+X^N

  • Guest
? create UCS at 'double' angle to WCS via AutoLISP
« on: September 12, 2016, 10:04:18 PM »
Now I need to learn more about how to handle angles in AutoLISP .
And how to handle arrays of data in AutoLISP .
...
My task is to create MANY User Coordinate Systems ( UCS ) es at 'double' angles :
The FIRST is rotated in the World Coordinate System ( WCS ) , origin at a known point WCS (x1 y1 z1) (MANY of these) & with the X axis 'heading' towards the WCS origin (0 0 0) , my AutoLISP works for that ;

then while active in this (these many ucs es) ,
the SECOND UCS Z axis is 'tipped' [ 1 / 2 ] of the way 'rotated' towards a (single) known point WCS (x_important y_important z_important) .
{I did this manually by drawing an arc then a line to the mid_of , in order to define the 'second' ucs .}
..
The last UCS I derived while in the 'second' by creating a 'design surface' to make sure that the overall height was good ;
then Menu >> 3D Operations >> Extract iso line & I made one at the origin of the present UCS there ,
it has an orientation straight in the WCS Y direction .
...
And I am just learning AutoLISP ...
...
Attached screen shots following are of :
1)  'first' UCS at an angle in the X-Y plane of WCS {can AutoLISP to get these}
2)  'second' UCS - with a 'design' surface - to be sure it fits & showing the (1 / 2 ) 'tipped' angle [need to AutoLISP these]
3) 'third' UCS _ un wound to be more or less square to the world along the top and bottom edges _ ISO_view [it'll be a miracle if I can AutoLISP these]
4) a few of the 'third' UCS es and final surfaces that I did by hand _ISO_view
« Last Edit: September 12, 2016, 10:34:42 PM by +X^N »

Stefan

  • Bull Frog
  • Posts: 220
Re: ? create UCS at 'double' angle to WCS via AutoLISP
« Reply #1 on: September 13, 2016, 03:54:55 AM »
If "o" is the origin of the new UCS and "p" is the "important point" (both expressed in WCS), this is how you can
get the orientation of the new UCS axis:
Code - Auto/Visual Lisp: [Select]
  1. ;n  = unit vector o->p
  2.     (setq n  (unv (mapcar '- p o)))
  3.  
  4. ;z1 = unit vector of middle between '(0 0 1) and n
  5.     (setq z1 (unv (m2p n '(0.0 0.0 1.0))))
  6.  
  7. ;a  = angle of z1 axis in yOz plan
  8.     (setq a (angle '(0 0) (list (caddr z1) (cadr z1))))
  9.  
  10. ;y1 = new UCSYDIR
  11.     (setq y1 (list 0.0 (cos a) (- (sin a))))
  12.  
  13. ;x1 = new UCSXDIR = cross product y1*z1
  14.     (setq x1 (v*v y1 z1))
  15.  
  16. ;New UCS definition
  17. (command "_ucs" "_3p"
  18.          "_non" (trans o 0 1)
  19.          "_non" (trans (mapcar '+ o x1) 0 1)
  20.          "_non" (trans (mapcar '+ o y1) 0 1)
  21. )
I know nothing about Iso Lines or how you do it, but if you explain a little more, i think it can be done by lisp.

+X^N

  • Guest
Re: ? create UCS at 'double' angle to WCS via AutoLISP
« Reply #2 on: September 13, 2016, 07:19:39 PM »
I got it _ up to the third of four UCS (User Coordinate System) at a 'double' angle with.respect.to (WRT) the WCS -
using the built in AutoLISP functions angle & polar to define the third UCS .
.
And I AutoLISP ed the surface & extract the u _ line using the AutoCAD command surfextractcurve .
..
See the screen shot below .
The finalt UCS es & surfaces I did manually are seen next to the one I was testing the AutoLISP on (left & right) .
...
See the screenshots 2 , 3 above , that I did manually .
At present the routine is at 2 --
need to be at 3 :
Now I need to AutoLISP the picking of the 'far end' of that line to help define the last UCS -
at the 'double angle' & at much as possible 'square _ to _ the _ world' .
« Last Edit: September 13, 2016, 07:27:27 PM by +X^N »

+X^N

  • Guest
Re: ? create UCS at 'double' angle to WCS via AutoLISP
« Reply #3 on: September 13, 2016, 07:33:54 PM »
If "o" is the origin of the new UCS and "p" is the "important point" (both expressed in WCS), this is how you can
get the orientation of the new UCS axis:
<snip>
I know nothing about Iso Lines or how you do it, but if you explain a little more, i think it can be done by lisp.
Thank you very much for that code ; I did it using the AutoLISP built in function angle , then / 2 ;
then used that  in the AutoLISP built in function polar to get a cartesian ordered pair to define the X axis in the new UCS .

+X^N

  • Guest
Re: ? create UCS at 'double' angle to WCS via AutoLISP
« Reply #4 on: September 13, 2016, 09:48:52 PM »
Probably can get the 'top' end of the u _ line : "The AutoLisp Intermediate Tutorial - Entity DXF Group Codes "
http://www.jefferypsanders.com/autolispintr_dxf.html :
Code - Auto/Visual Lisp: [Select]
  1. (setq entnow (entget(car(entlast))))
  2. (setq _pnt_entnow2 (assoc 11 entList))
  3.  
in order to use that end point in the last UCS .
.
Have not tested yet ;
will post pict when done testing .

+X^N

  • Guest
Re: ? create UCS at 'double' angle to WCS via AutoLISP
« Reply #5 on: September 14, 2016, 11:43:07 AM »
If "o" is the origin of the new UCS and "p" is the "important point" (both expressed in WCS), this is how you can
get the orientation of the new UCS axis:
Code - Auto/Visual Lisp: [Select]
  1. ;n  = unit vector o->p
  2.   <snip>
  3. ;New UCS definition
  4. (command "_ucs" "_3p"
  5.          "_non" (trans o 0 1)
  6.          "_non" (trans (mapcar '+ o x1) 0 1)
  7.          "_non" (trans (mapcar '+ o y1) 0 1)
  8. )
I know nothing about Iso Lines or how you do it, but if you explain a little more, i think it can be done by lisp.
This looks excelent --
will probably need to use for the 'last' step of setting the UCS es 'as square to the world as possible' .
See picts 2 - 3 in first set of 4 picts .
..
I remember vectors from analytic geometry :
unit vectors , normals , cross product , ect --
although am a bit rusty .
..
I will need to learn about those AutoLISP commands .
Just read up on http://www.theswamp.org/~john/avlisp/#trans _ it is a beautiful function - "just what (the doctor) Descartes ordered" .
? Cannot find info on :
unv
m2p
v*v
?
...
Vectors Yea !
...
« Last Edit: September 14, 2016, 12:25:07 PM by +X^N »

Stefan

  • Bull Frog
  • Posts: 220
Re: ? create UCS at 'double' angle to WCS via AutoLISP
« Reply #6 on: September 14, 2016, 02:00:50 PM »
? Cannot find info on :
unv
m2p
v*v
?
...
Vectors Yea !
...
LMGTFY
Meanwhile, try this lisp. First, pick the target point and set the square's length, then pick the base point of the new UCS.
Code - Auto/Visual Lisp: [Select]
  1. ;Stefan M. - 14.09.2016
  2. ;Draw reflecting panels
  3. (defun c:test ( / m2p unv v*v p d o n a x y z)
  4.   (defun m2p (a b)                                     ;middle point
  5.     (mapcar '(lambda (a b) (/ (+ a b) 2.0)) a b)
  6.   )
  7.   (defun unv (v / d)                                   ;unit vector
  8.     (setq d (distance '(0.0 0.0 0.0) v))
  9.     (mapcar '(lambda (a) (/ a d)) v)
  10.   )
  11.   (defun v*v (a b)                                     ;cross product
  12.     (list
  13.       (- (* (cadr  a) (caddr b)) (* (caddr a) (cadr  b)))
  14.       (- (* (caddr a) (car   b)) (* (car   a) (caddr b)))
  15.       (- (* (car   a) (cadr  b)) (* (cadr  a) (car   b)))
  16.     )
  17.   )
  18.  
  19.   (if
  20.     (and
  21.       (setq p (getpoint "\nSpecify target point: "))
  22.       (setq d (getdist "\nSpecify square length: "))
  23.       )
  24.     (progn
  25.       (setq p (trans p 1 0))
  26.       (while
  27.         (setq o (getpoint "\nSpecify base point: "))
  28.         (setq o (trans o 1 0)
  29.               n (unv (mapcar '- p o))
  30.               z (unv (m2p n '(0.0 0.0 1.0)))
  31.               a (angle '(0.0 0.0) (list (caddr z) (cadr z)))
  32.               y (list 0.0 (cos a) (- (sin a)))
  33.               x (v*v y z)
  34.               )
  35.         (command "_ucs" "_3p"
  36.                  "_non" (trans o 0 1)
  37.                  "_non" (trans (mapcar '+ o x) 0 1)
  38.                  "_non" (trans (mapcar '+ o y) 0 1)
  39.                  )
  40.         (command "_planesurf" ;or "_rectang"
  41.                  "_non" (list (/ d -2) (/ d -2))
  42.                  "_non" (list (/ d  2) (/ d  2))
  43.                  )
  44.         )
  45.       )
  46.     )
  47.   (princ)
  48. )