### Author Topic: Convert GEOMCAL functions to LISP  (Read 30726 times)

0 Members and 1 Guest are viewing this topic.

#### xiaxiang

• Guest
##### Re: Convert GEOMCAL functions to LISP
« Reply #30 on: March 07, 2011, 08:47:39 PM »
there's an excellent trig library around the internet
Quote
Author: Gregory Cherevko
http://www.elecran.com.ua/
===========================

Wonderful
Thanks
Greetings
Great!
Deep in love with it

#### gschmidt

• Guest
##### Re: Convert GEOMCAL functions to LISP
« Reply #31 on: March 10, 2011, 11:02:33 AM »
Hi gile,

This one is correct! Thanx....

I will check the other ones asap (very busy at the moment)

Greetzzz,

Gerben

Hi,

Code: [Select]
`;; NOR(p1,p2)(defun Norm2Pts (p1 p2)  ((lambda (v)     (vunit (list (- (cadr v)) (car v) 0.0))   )    (mapcar '- p2 p1)  ));;; VUNIT;;; Returns the single unit vector of a vector;;;;;; Argument = a vector(defun vunit (v)  ((lambda (l)     (if (/= 0 l)       (mapcar (function (lambda (x) (/ x l))) v)     )   )    (distance '(0 0 0) v)  ))`

#### gschmidt

• Guest
##### Re: Convert GEOMCAL functions to LISP
« Reply #32 on: March 15, 2011, 06:47:35 AM »
Hi,

I tested the ROT function of gile (please correct me if I mistyped the code):

This function I try currenly:

Code: [Select]
`(defun rot3d (pt ax1 ax2 ang)  ((lambda (v)     (mapcar '+      ax1      (trans        (mxv (list (list (cos ang) (- (sin ang)) 0.)        (list (sin ang) (cos ang) 0.)        '(0. 0. 1.) ) (trans (mapcar '- pt ax1) 0 v)        )        v        0      )     )   )    (mapcar '- ax2 ax1)  );; MXV;; Apply a transformation matrix to a vector -Vladimir Nesterovsky-(defun mxv (m v)  (mapcar (function (lambda (r) (apply '+ (mapcar '* r v)))) m))`
Example of Input:
smallarc      = 6.64126
arccen1         = (7.92513 4.54529 -5.0)
arccen2         = (7.92513 4.54529 45.0)
ptempprev      = (-2.40231 -6.33332 -5.0)

Both Codes compared:

(setq ptempnow (cal "rot(ptempprev,arccen1,arccen2,smallarc)"))
(setq ptempnow1 (rot3d ptempprev arccen1 arccen2 smallarc))

Both Codes Output:
(print ptempnow)   = (-1.07487 -7.45471 -5.0)
(print ptempnow1)   = (2.06541 -9.26282 -5.0)

They don't match? Did I mistype something here?

You're right Lee, I forgot some statements

Code: [Select]
`(defun rot3d (pt ax1 ax2 ang)  ((lambda (v)     (mapcar '+     ax1     (trans       (mxv (list (list (cos ang) (- (sin ang)) 0.)       (list (sin ang) (cos ang) 0.)       '(0. 0. 1.) ) (trans (mapcar '- pt ax1) 0 v)       )       v       0     )     )   )    (mapcar '- ax2 ax1)  ))`

#### gschmidt

• Guest
##### Re: Convert GEOMCAL functions to LISP
« Reply #33 on: March 16, 2011, 11:22:30 AM »
Hi,

The ANGLE code works too...thanx!

G

Code: [Select]
`(defun LM:GetApexAngle ( apex p1 p2 )  (- (+ pi pi) (rem (+ pi pi (- (angle apex p1) (angle apex p2))) (+ pi pi))))`[/quote]

#### gschmidt

• Guest
##### Re: Convert GEOMCAL functions to LISP
« Reply #34 on: March 18, 2011, 09:17:21 AM »
Hi,

Still looking for the GEOMCAL "ROT" function.

I tested now 2 funtions:

- gile (rot3d)
- the 3dlib (funtion(s) joined together)

Code: [Select]
`(defun 3d_rotatept1 (p p1 p2 ang / sina cosa wekt) (setq wekt (3d_ort (mapcar '- p2 p1)) sina (sin ang) cosa (cos ang)) (if (3d_ptonline p1 wekt p)  p  (progn   (setq p (trans (mapcar '- p p1) 0 wekt))   (mapcar '+ (trans (list (- (* (car p) cosa) (* (cadr p) sina))                           (+ (* (car p) sina) (* (cadr p) cosa))                           (caddr p)                     )                     wekt 0              )              p1   )  ) ))(defun 3d_ptonline (p p1 wekt1 / wekt2) (setq wekt2 (mapcar '- p p1)) (and (equal (* (car wekt1) (cadr wekt2)) (* (cadr wekt1) (car wekt2)) 0.00001)      (equal (* (car wekt1) (caddr wekt2)) (* (caddr wekt1) (car wekt2)) 0.00001)      (equal (* (cadr wekt1) (caddr wekt2)) (* (caddr wekt1) (cadr wekt2)) 0.00001) ))(defun 3d_ort (wekt / d k) (if (equal (setq d (distance '(0.0 0.0 0.0) wekt)) 1.0 0.00001)  wekt  (if (equal d 0.0 0.00001) '(0.0 0.0 0.0) (progn (setq k (/ 1.0 d)) (mapcar '(lambda (v) (* v k)) wekt))) ))`
Both of them had the same answer, but still not equal to the GEOMCAL!

The code that I was asking for is part of a LISP code that draws by selecting a Top Plane (closed 3d-polyline) a 3d-wire model (lines) with side slopes,
where all lines on the ground plane have a certain elevation/depth.

I know that the GEOMCAL ROT function works fine because the wire-model is drawn correct, but is not correct drawn when I use the "gile" or "3dlib" functions.
Attached are the LISP and an simple example of a closed 3dpolyline.

Notes:
- When running the LISP, the question: "LENGTH of a face, 0 means faces extended to lowest point found on 3D Polyline" must be set to 0 (is also default).
- Around row 474 is the ROTATION issue

« Last Edit: March 18, 2011, 09:34:46 AM by gschmidt »

#### gile

• Water Moccasin
• Posts: 2450
• Marseille, France
##### Re: Convert GEOMCAL functions to LISP
« Reply #35 on: March 18, 2011, 04:30:31 PM »
Hi,

rot3d returns the same result as the geomcal, but rot3d requires the angle to be expressed in radians when the geomcal requires angles in the current angle unit.
Speaking English as a French Frog

#### ribarm

• Gator
• Posts: 3103
• Marko Ribar, architect
##### Re: Convert GEOMCAL functions to LISP
« Reply #36 on: March 19, 2011, 08:42:02 AM »
Hi to everyone, I am new member of this site and I've found here some interesting topics...

I am interested could someone help me to solve this problem :

I want to calculate center point that is obtained from list of points... Using geomcal.arx (cal function) is difficult, for I don't know how to pass more points from list into 'cal... I suppose there is better way using lisp... mapcar in combination with lambda... For now I can do this by creating polyline that I convert to region and obtain Centroid of that region. (but this is also confusing process)... With geomcal, I just used
Code: [Select]
`(setq cent (cal "(pt1+pt2+pt3+...+ptn)/n"))`
Any help is very much appreciated...

M.R.

BTW. What if points are not coplanar (I could never create polyline and region after)? Only way is to calculate by lisp or by passing list of points into 'cal
« Last Edit: March 19, 2011, 09:12:45 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

#### gile

• Water Moccasin
• Posts: 2450
• Marseille, France
##### Re: Convert GEOMCAL functions to LISP
« Reply #37 on: March 19, 2011, 09:21:08 AM »
Hi,

First, calculating coordinates average of a polyline vertices won't return the centroid of the polyline if it has more than 3 vertices or if it's not a regular polygon.

If you want the centroid, you can use the 'pline-centroid' sub routine posted here.

If you want the average of a point list (I do not know the English word for: barycentre), you can get it this way:
Code: [Select]
`(mapcar '(lambda (x) (/ x (length lst))) (apply 'mapcar (cons '+ lst)))`
« Last Edit: March 19, 2011, 10:16:18 AM by gile »
Speaking English as a French Frog

#### ribarm

• Gator
• Posts: 3103
• Marko Ribar, architect
##### Re: Convert GEOMCAL functions to LISP
« Reply #38 on: March 19, 2011, 09:46:49 AM »
I see what you thought, but still this formula has to be passed to 'cal, for standard operations in auto lisp are determined to work only with numbers, but not with points and list of points as in our case...

Any idea?

M.R.

BTW. For list of numbers correct code would be :
Code: [Select]
`(/ (apply (function +) lst) (float (length lst)))`
« Last Edit: March 19, 2011, 09:52:49 AM by ribarm »
Marko Ribar, d.i.a. (graduated engineer of architecture)

#### Lee Mac

• Seagull
• Posts: 12828
• London, England
##### Re: Convert GEOMCAL functions to LISP
« Reply #39 on: March 19, 2011, 10:17:01 AM »
?

Code: [Select]
`(defun Mid ( _pointlist )  ( (lambda ( l ) (mapcar '/ (apply 'mapcar (cons '+ _pointlist)) (list l l l)))    (float (length _pointlist))  ))`

#### ribarm

• Gator
• Posts: 3103
• Marko Ribar, architect
##### Re: Convert GEOMCAL functions to LISP
« Reply #40 on: March 19, 2011, 10:27:49 AM »
I figured this one :

Code: [Select]
`(defun cent (lst)(setq centptx (/ (apply (function +) (mapcar (function car) lst)) (float (length lst))))(setq centpty (/ (apply (function +) (mapcar (function cadr) lst)) (float (length lst))))(setq centptz (/ (apply (function +) (mapcar (function caddr)lst)) (float (length lst))))(setq centpt (list centptx centpty centptz)))`
M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

#### Lee Mac

• Seagull
• Posts: 12828
• London, England
##### Re: Convert GEOMCAL functions to LISP
« Reply #41 on: March 19, 2011, 10:57:28 AM »
That is equivalent to my code

#### gschmidt

• Guest
##### Re: Convert GEOMCAL functions to LISP
« Reply #42 on: March 21, 2011, 03:45:12 AM »
Come on....that easy?....I spent quit a time figuring out why...haha....thanx Gile, your right!

G

Hi,

rot3d returns the same result as the geomcal, but rot3d requires the angle to be expressed in radians when the geomcal requires angles in the current angle unit.

#### chlh_jd

• Guest
##### Re: Convert GEOMCAL functions to LISP
« Reply #43 on: April 04, 2011, 10:53:44 PM »
Hi Landlord, Today have some time to read this
`(defun midpts (lst / len)  (setq len (length lst))  (mapcar (function (lambda (x) (/ x len)))   (apply (function mapcar) (cons (function +) lst))  ))`if have 2d point in the pts , can use this fun
`(defun midpts (lst)  (mapcar (function (lambda (x) (/ x (length lst))))  (apply 'mapcar (cons '+       (mapcar (function (lambda (y)   (trans y 0 0) )       )       lst       ) )  )  ))`