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

0 Members and 1 Guest are viewing this topic.

SOFITO_SOFT

  • Guest
Re: Convert GEOMCAL functions to LISP
« Reply #15 on: March 05, 2011, 03:05:21 PM »
Hello:
Another little thing... but critical !:
To initialize variables in the start of your program to insert the line
Code: [Select]
(Setq
   $P000   '( 0.0 0.0 0.0 )
   $Dopusk  0.00001
   2pi ( * 2 pi )
)
Some functions use the variable 2pi, but I do not see where is initialized
I'm falling for this LIB. :lol: :lol: :lol:  Здоровье друзей !!! 
Regards. :-)

SOFITO_SOFT

  • Guest
Re: Convert GEOMCAL functions to LISP
« Reply #16 on: March 06, 2011, 12:08:42 PM »
Hello:
Some notes on 3d_lib:
Var names:
Pn - the inicial point of an arc 
Pk - the final point of an arc
 

Also must be initialized
_2pi  = * -2 pi

This function does not provide for inside circles case. I believe that with the additional work in this case ¿? :|
Code: [Select]
;The intersection of 2 circles given center and radius, coplanar  ( 10.zip ) 
 ( defun 2d_inters_circle  ( P1 R1 P2 R2 / A A1 CosA D )
  ( setq D  ( distance P1 P2 )    A1  ( angle P1 P2 )  )
  ( cond
   (  (  =/ D  ( + R1 R2 )   )   ( list  ( polar P1 A1 R1 )   ( polar P1 A1 R1 )  )  )
   (  ( > D  ( + R1 R2 )  )  nil )
;**********************************
   (  ( <  (  + D  (  min r1 r2  )  )   ( max R1 R2 )  )  nil )
;**********************************
   ( T
    ( setq CosA  ( /  ( -  ( +  ( * R1 R1 )   ( * D D )  )   ( * R2 R2 )  )  2.0 R1 D )
         A  ( atan  ( sqrt  ( - 1  ( * CosA CosA )  )  )  CosA )
    )
    ( list  ( polar P1  ( + A1 A )  R1 )   ( polar P1  ( - A1 A )  R1 )  )
   )
  )
 )
Greetings  :-)

gschmidt

  • Guest
Re: Convert GEOMCAL functions to LISP
« Reply #17 on: March 07, 2011, 02:54:33 AM »
Hi there,

Thanx for the help sofar.

The "normal vector" output did not match the cal "NOR(p1,p2)"
I will give an example of p1 and p2 and the answer that the GEOMCAL returns:

p1 = (0.192187 1.74006 -852.17)
p2 = (0.682187 2.62006 -852.19)
answer = (-0.873689 0.486486 0.0)
note: z-coord is always 0.0

your codes answer: (0.48639 0.873516 -0.0198526)

I will check the other stuff asap...


(cal "NOR(p1,p2)") = (vec1 p1 p2)
(cal "PLD(p1,p2,distance)") = (3d_polarp p1 p2 l)
Code: [Select]
;;; 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)
  )
)
;;; VEC1
;;; Returns the single unit vector from p1 to p2
;;;
;;; Arguments = two points
(defun vec1 (p1 p2)
  (vunit (mapcar '- p2 p1))
)
(defun 3d_polarp (P1 P2 L)
 (setq L (/ L (distance P1 P2)))
 (mapcar '+ P1 (mapcar '(lambda (V) (* V L)) (mapcar '- P2 P1)))
)



gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Convert GEOMCAL functions to LISP
« Reply #18 on: March 07, 2011, 03:35:26 AM »
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)
  )
)
Speaking English as a French Frog

gschmidt

  • Guest
Re: Convert GEOMCAL functions to LISP
« Reply #19 on: March 07, 2011, 03:47:02 AM »
Hi Lee,

tested your ANGLE code:
Here is an example of input coords and angle results

p1 = (0.192187 1.74006 -852.17)
pc11 = (13.1945 -6.5494 -857.31)
pc12 = (14.0867 -4.94716 -857.31)
pc21 = (13.634 -5.63714 -857.31)
pc22 = (14.5226 -4.04114 -857.31)

Code: [Select]
(setq ang11 (cal "ang(pc11,p1,pc21)"))
(print ang11) = 276.8 = GEOMCAL answer

(setq ang22 (cal "ang(pc12,p1,pc22)"))
(print ang22) = 270.006 = GEOMCAL answer

;; Your Code ( I hope I wrote it down the way you mean it!)

(setq test (* 180. (min (setq a (rem (+ pi pi (- (angle p1 pc12) (angle p1 pc22))) (+ pi pi))) (- (+ pi pi) a)) pi))
(print test) = 36.82 = LEE MAC answer


For

(cal "ANG(apex,p1,p2)") =
-returns the angle (in degrees or decimal degrees) between the lines "apex-p1" and "apex-p2".

Would this be what is needed?

Code: [Select]
(defun LM:GetApexAngle ( p1 p2 p3 )
  (min (setq a (rem (+ pi pi (- (angle p2 p1) (angle p2 p3))) (+ pi pi))) (- (+ pi pi) a))
)

And in degrees:

Code: [Select]
(* 180. (/ (LM:GetApexAngle <p1> <p2> <p3>) pi))
 Returns the acute angle between three points.

SOFITO_SOFT

  • Guest
Re: Convert GEOMCAL functions to LISP
« Reply #20 on: March 07, 2011, 04:14:04 AM »
Hi all:
this is correct:
p1 = (0.192187 1.74006 -852.17)
p2 = (0.682187 2.62006 -852.19)
answer = (-0.873689 0.486486 0.0)
note: z-coord is always 0.0

please , draw a line form p1 to p2  ( only XY )
the line from (0 0 0) to (-0.873689 0.486486 0.0)  is normal to line p1-p2 but only IN 2D !!!
"NOR(p1,p2)" is only for 2D dimension....
No one can calculate the nomal vector to the line p1 p2 in 3Dspace, since there are infinite solutions.
So he always gives Z = 0.0
Greetings.
 

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Convert GEOMCAL functions to LISP
« Reply #21 on: March 07, 2011, 04:47:02 AM »

gschmidt 

Have a look at post Reply #10

The code in that post is correct.


I think the CAL answer for your second example is incorrect
these are the answers I get :

(setq p1   '(0.192187 1.74006 0.)
      pc11 '(13.1945 -6.5494 0.)
      pc12 '(14.0867 -4.94716 0.)
      pc21 '(13.634 -5.63714 0.)
      pc22 '(14.5226 -4.04114 0.)
)
(kdub:rtd (kdub:Enclosed_ang-vertex-pt-pt pc11 p1 pc21)) ;-> 276.796
(kdub:rtd (kdub:Enclosed_ang-vertex-pt-pt pc12 p1 pc22)) ;-> 270.008
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.

SOFITO_SOFT

  • Guest
Re: Convert GEOMCAL functions to LISP
« Reply #22 on: March 07, 2011, 04:58:30 AM »
Hello again:
note: z-coord is always 0.0 <<<< !!! :-o
If you expect a 3D point you have to deal p1 and p2 as 2 vectors.
If you do the cross product "(Wedge)" of the 2 vectors (0,0,0) - p1 & (0,0,0) - p2, then you get the solution of a 3Dvector perpendicular to the plane are (0,0,0)-p1-p2.
The vector for this case is (749,875 - 417,559, -0.683505).
If you reduce the length to 1 (unit vector) then get (0.873681, -0.486499, -0.000796353)
You can draw the data and verify that the new vector is perpendicular a (0,0,0)-p1 & (0,0,0)-p2 (in their respectives planes ) .
I hope I have solved your questions on the normal vector and its Z coord.
Greetings. :-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Convert GEOMCAL functions to LISP
« Reply #23 on: March 07, 2011, 05:00:50 AM »
SOFITO_SOFT
Who are you talking at and in relation to what ?

added:
The result from  NOR(p1,p2) will always be z=0 as you (and the help files) indicate.
However, the input CAN be 3d
ie
Quote
Command: !p1
(0.192187 1.74006 -852.17)

Command: !p2
(0.682187 2.62006 -852.19)

Command: CAL
>> Expression: nor(p1,p2)
-0.873688555,0.486485672,0

Simarly, with the code by gile PostReply#18
Code: [Select]
(setq p1 '(0.192187 1.74006 -852.17)
      p2 '(0.682187 2.62006 -852.19)
      p11 '(0.192187 1.74006 0.)
      p12 '(0.682187 2.62006 42.42)
)

(Norm2Pts p1 p2)   ;-> (-0.873689 0.486486 0.0)
(Norm2Pts p11 p12) ;-> (-0.873689 0.486486 0.0)
« Last Edit: March 07, 2011, 05:42:24 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.

SOFITO_SOFT

  • Guest
Re: Convert GEOMCAL functions to LISP
« Reply #24 on: March 07, 2011, 05:51:22 AM »
The "normal vector" output did not match the cal "NOR(p1,p2)"
I will give an example of p1 and p2 and the answer that the GEOMCAL returns:
p1 = (0.192187 1.74006 -852.17)
p2 = (0.682187 2.62006 -852.19)
answer = (-0.873689 0.486486 0.0)
note: z-coord is always 0.0
Despite what you say (rightly), gschmidt tries a "NOR..." with 3D points.!!!
Regards. :-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Convert GEOMCAL functions to LISP
« Reply #25 on: March 07, 2011, 05:54:39 AM »
The "normal vector" output did not match the cal "NOR(p1,p2)"
I will give an example of p1 and p2 and the answer that the GEOMCAL returns:
p1 = (0.192187 1.74006 -852.17)
p2 = (0.682187 2.62006 -852.19)
answer = (-0.873689 0.486486 0.0)
note: z-coord is always 0.0
Despite what you say (rightly), gschmidt tries a "NOR..." with 3D points.!!!
Regards. :-)

Yes, and that is perfectly acceptable ... or don't you agree ?
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.

SOFITO_SOFT

  • Guest
Re: Convert GEOMCAL functions to LISP
« Reply #26 on: March 07, 2011, 07:55:15 AM »
Hello:
perfectly acceptable, i agree but gschmidt seems strange and he compares with another method.
answer = (-0.873689 0.486486 0.0)
note: z-coord is always 0.0
your codes answer: (0.48639 0.873516 -0.0198526)

It seems that he sees a contradiction. no?
Or is that too much Monday ? but it is also possible that I have much on top Sunday.
Regards.  :-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Convert GEOMCAL functions to LISP
« Reply #27 on: March 07, 2011, 08:20:12 AM »
Sorry, I'm having trouble understanding the point you are trying to make.
my problem, not yours , I think :)


To replace (cal "NOR(p1,p2)") ..
I do understand that code by VVA
(vec1 p1 p2)
 returns an incorrect answer.

Code by Giles
(Norm2Pts  p1 p2)
returns the correct answer.

Passing 3D points to  both (cal "NOR(p1,p2)")  and  (Norm2Pts  p1 p2) return the expected result as 2D


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.

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Convert GEOMCAL functions to LISP
« Reply #28 on: March 07, 2011, 02:58:49 PM »
Kerry, what/where are these codes?

(kdub:rtd (kdub:Enclosed_ang-vertex-pt-pt pc11 p1 pc21)) ;-> 276.796
(kdub:rtd (kdub:Enclosed_ang-vertex-pt-pt pc12 p1 pc22)) ;-> 270.008

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Convert GEOMCAL functions to LISP
« Reply #29 on: March 07, 2011, 08:09:41 PM »
Kerry, what/where are these codes?

(kdub:rtd (kdub:Enclosed_ang-vertex-pt-pt pc11 p1 pc21)) ;-> 276.796
(kdub:rtd (kdub:Enclosed_ang-vertex-pt-pt pc12 p1 pc22)) ;-> 270.008

That's some stuff from one of my librarys that is slightly less elegant than your Post #10 (but essentially similar functionality)
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.