Author Topic: how to permute the y by the z values of a point  (Read 3842 times)

0 Members and 1 Guest are viewing this topic.

DEVITG

  • Bull Frog
  • Posts: 481
how to permute the y by the z values of a point
« on: February 14, 2005, 03:26:24 PM »
Hi all .

I have this points whos Y values shall be permuted  with the Z Values , so all the Y becomes Z and the Z becomes Y .
It is like to rotate the all poinst  90 degree by the x axis.
This point are the coordenates of 12 radii spaced 7.5 degree on a half circle.


Code: [Select]
(setq k1(200.0 0.0 0.0)
(setq k2(199.144 13.0526 0.0)
(setq k3(196.593 25.8819 0.0)
(setq k4(192.388 38.2683 0.0)
(setq k5(186.603 50.0 0.0)
(setq k6(179.335 60.8761 0.0)
(setq k7(170.711 70.7107 0.0)
(setq k8(160.876 79.3353 0.0)
(setq k9(150.0 86.6025 0.0)
(setq k10(138.268 92.388 0.0)
(setq k11(125.882 96.5926 0.0)
(setq k12(113.053 99.1445 0.0)
(setq k13(100.0 100.0 0.0)


The result shall be
Code: [Select]
(setq k1(200.0 0 0)
(setq k2(199.144 0 13.0526)
(setq k3(196.593 0 25.8819)
(setq k4(192.388 0 38.2683)
(setq k5(186.603 0 50)
(setq k6(179.335 0 60.8761)
(setq k7(170.711 0 70.7107)
(setq k8(160.876 0 79.3353)
(setq k9(150.0 0 86.6025)
(setq k10(138.268 0 92.388)
(setq k11(125.882 0 96.5926)
(setq k12(113.053 0 99.1445)
(setq k13(100.0 0 100)


I see about the Trans function , but I can not understand it.

Thanks in advance.
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
how to permute the y by the z values of a point
« Reply #1 on: February 14, 2005, 04:26:00 PM »
Here's a simple approach....
Code: [Select]
(defun permute_yz (pt / )
  (list (car pt) (caddr pt) (cadr pt))
  )

whdjr

  • Guest
how to permute the y by the z values of a point
« Reply #2 on: February 14, 2005, 04:59:25 PM »
Simplicity is normally the best approach.

MP (not logged in)

  • Guest
how to permute the y by the z values of a point
« Reply #3 on: February 14, 2005, 05:21:12 PM »
Just for fun --

Code: [Select]
(defun SwapCoords ( point fx fy fz)  
    (list
        (fx point)
        (fy point)
        (fz point)
    )
)    

(SwapCoords '(1 2 3) car caddr cadr)

=> (1 3 2)

:)

JohnK

  • Administrator
  • Seagull
  • Posts: 10651
how to permute the y by the z values of a point
« Reply #4 on: February 14, 2005, 05:37:49 PM »
HA?! Awesome!

Heres mine. (BTW, Jeff, you stole my idea ...again?! :P I had to think of a diff way to do this for a second. *lol*)

Code: [Select]
(defun swap_yz (lst)
  (if (not (eq (length lst) 3))
    lst
    (cons (car lst) (reverse (cdr lst)))))
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
how to permute the y by the z values of a point
« Reply #5 on: February 14, 2005, 06:12:17 PM »
Is nth too slow?
Code: [Select]
(defun SwapCoords ( point xn yn zn)  
    (list
        (nth xn point)
        (nth yn point)
        (nth zn point)
    )
)    

(print (SwapCoords '(11 22 33) 0 2 1)) ; new order, 0 based
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
how to permute the y by the z values of a point
« Reply #6 on: February 14, 2005, 07:06:14 PM »
Quote from: CAB
Is nth too slow?
Code: [Select]
(defun SwapCoords ( point fx fy fz)  
    (list
        (nth fx point)
        (nth fy point)
        (nth fz point)
    )
)    

(print (SwapCoords '(11 22 33) 0 2 1)) ; new order, 0 based

Neglible performance hit. Probably more intuitive to use nth values (as opposed to car et al), but I would rename the arguments to something more appropriate, like xn yn zn.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
how to permute the y by the z values of a point
« Reply #7 on: February 14, 2005, 07:21:52 PM »
Thank you Sir,
Your wish is my command.

Not really, it just sounds cool. 8)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

DEVITG

  • Bull Frog
  • Posts: 481
sweping values
« Reply #8 on: February 14, 2005, 08:45:21 PM »
Hi all , tahnks for it , I will try it .

BTW , how to do it to all the point?

Tanks in advance
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
how to permute the y by the z values of a point
« Reply #9 on: February 14, 2005, 09:04:22 PM »
Personally I don't see the need for all those individual variables (k1 thru kn), but then again, I don't have the benefit of knowing the context of how the data will be used.

Anyway, if I had a hard list of point values this is how I might do it --

Code: [Select]
(setq points
   '(
        (200.0 0.0 0.0)
        (199.144 13.0526 0.0)
        (196.593 25.8819 0.0)
        (192.388 38.2683 0.0)
        (186.603 50.0 0.0)
        (179.335 60.8761 0.0)
        (170.711 70.7107 0.0)
        (160.876 79.3353 0.0)
        (150.0 86.6025 0.0)
        (138.268 92.388 0.0)
        (125.882 96.5926 0.0)
        (113.053 99.1445 0.0)
        (100.0 100.0 0.0)
    )    
)

(setq pointsXZY
    (mapcar
       '(lambda (point)
            (list
                (car point)
                (caddr point)
                (cadr point)
            )
        )
        points
    )  
)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst