TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: gschmidt on March 03, 2011, 05:26:07 AM

Title: Convert GEOMCAL functions to LISP
Post by: gschmidt on March 03, 2011, 05:26:07 AM
Hi,

I have an existing LISP build for AutoCAD which uses GEOMCAL functions.
I want to run this LISP also in BricsCAD however there is no GEOMCAL build in.

Now I want to convert 4 functions to LISP:

(cal "NOR(p1,p2)") =
- returns the normal vector to the vector between p1 and p2

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

(cal "ROT(rp,ax1,ax2,angle)") =
- returns the point that is the result of the 3D rotation of point rp around the axis through ax1 and ax2 with the given rotation angle. The angle is given,in degrees and/or decimal degrees and is measured counterclockwise.

(cal "PLD(p1,p2,distance)") =
-returns the coordinate point that is on the line between p1 and p2 in the given distance from p1


Greetzzz,

Gerben




 





 
Title: Re: Convert GEOMCAL functions to LISP
Post by: VVA on March 04, 2011, 11:21:27 AM
(cal "NOR(p1,p2)") = (vec1 p1 p2) (see Norm2Pts by gile below)
(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)))
)

Title: Re: Convert GEOMCAL functions to LISP
Post by: Lee Mac on March 04, 2011, 12:22:53 PM
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.
Title: Re: Convert GEOMCAL functions to LISP
Post by: gile on March 04, 2011, 04:25:21 PM
Hi,

Quote
(cal "ROT(rp,ax1,ax2,angle)") =
- returns the point that is the result of the 3D rotation of point rp around the axis through ax1 and ax2 with the given rotation angle. The angle is given,in degrees and/or decimal degrees and is measured counterclockwise.

This one needs to use a rotation matrix.

Code: [Select]
;; MXV
;; Apply a transformation matrix to a vector -Vladimir Nesterovsky-

(defun mxv (m v)
  (mapcar (function (lambda (r) (apply '+ (mapcar '* r v)))) m)
)

(defun rot3d (pt ax1 ax2 ang)
  ((lambda (v)
     (trans
       (mxv
(list (list (cos ang) (- (sin ang)) 0.)
       (list (sin ang) (cos ang) 0.)
       '(0. 0. 1.)
)
(trans pt 0 v)
       )
       v
       0
     )
   )
    (mapcar '- ax2 ax1)
  )
)
Title: Re: Convert GEOMCAL functions to LISP
Post by: Lee Mac on March 04, 2011, 06:22:37 PM
I think:

Code: [Select]
(defun rot3D ( pt ax1 ax2 ang )
  (
    (lambda ( m n / o v )
      (setq o (trans ax1 0 n)
            o (list (car o) (cadr o) 0.)
            v (mapcar '- o (mxv m o))
      )
      (trans (mapcar '+ (mxv m (trans pt 0 n)) v) n 0)
    )
    (list
      (list (cos ang) (- (sin ang)) 0.)
      (list (sin ang)    (cos ang)  0.)
      (list     0.        0.        1.)
    )
    (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)
)

Since the Coordinate frame of the Rotation Axis is defined relative to the origin.
Title: Re: Convert GEOMCAL functions to LISP
Post by: Kerry on March 04, 2011, 07:13:34 PM


Lee, you may want to have another look at your ANG conversion, for a couple of reasons ..

The expected input is <Apex> <P1> <P2>
and the expected output is the enclosed angle, measured anti-clockwise, between the vectors Apex->P1 and Apex->P2.

BTW, your routine does not return an acute angle (more than 0, less than 90) as you indicate,
it will return an angle  between 0 and 180

ps: unless I've misread your code.

Title: Re: Convert GEOMCAL functions to LISP
Post by: gile on March 04, 2011, 07:39:11 PM
You're right Lee, I forgot some statements :oops:

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)
  )
)
Title: Re: Convert GEOMCAL functions to LISP
Post by: Lee Mac on March 04, 2011, 07:40:42 PM
BTW, your routine does not return an acute angle (more than 0, less than 90) as you indicate,
it will return an angle  between 0 and 180

Apologies - no it isn't 'acute', I meant the angle opposite to the reflex angle, which of course could be obtuse or acute...

From the description in your post, the order of the arguments in my original code is incorrect I suppose, I assumed:

Code: [Select]
(LM:GetApexAngle <p1> <Apex> <p3>)
This could of course be ammended by switching the symbols around:

Code: [Select]
(defun LM:GetApexAngle ( apex p1 p2 )
  (min (setq a (rem (+ pi pi (- (angle apex p1) (angle apex p2))) (+ pi pi))) (- (+ pi pi) a))
)
Title: Re: Convert GEOMCAL functions to LISP
Post by: Lee Mac on March 04, 2011, 07:50:01 PM
You're right Lee, I forgot some statements :oops:

Code: [Select]
(defun rot3d (pt ax1 ax2 ang) < .. snip .. >

Much better than my code!
Title: Re: Convert GEOMCAL functions to LISP
Post by: Kerry on March 04, 2011, 08:01:19 PM
< .. >
This could of course be ammended by switching the symbols around:

Code: [Select]
(defun LM:GetApexAngle ( apex p1 p2 )
  < .. >
)

Yep.

Now you just need this :
Quote
and the expected output is the enclosed angle, measured anti-clockwise, between the vectors Apex->P1 and Apex->P2.


Title: Re: Convert GEOMCAL functions to LISP
Post by: Lee Mac on March 04, 2011, 08:16:46 PM
< .. >
This could of course be ammended by switching the symbols around:

Code: [Select]
(defun LM:GetApexAngle ( apex p1 p2 )
  < .. >
)

Yep.

Now you just need this :
Quote
and the expected output is the enclosed angle, measured anti-clockwise, between the vectors Apex->P1 and Apex->P2.

I hadn't read the help file, so I assumed they wanted the smaller of the angles (as I decribed, the angle opposite the reflex angle).

If not, it simplifies my code somewhat:

Code: [Select]
(defun LM:GetApexAngle ( apex p1 p2 )
  (- (+ pi pi) (rem (+ pi pi (- (angle apex p1) (angle apex p2))) (+ pi pi)))
)
Title: Re: Convert GEOMCAL functions to LISP
Post by: Kerry on March 04, 2011, 08:47:41 PM
< .. >  it simplifies my code somewhat:

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

That looks like is should do very nicely.  :wink:
Title: Re: Convert GEOMCAL functions to LISP
Post by: VovKa on March 05, 2011, 04:48:02 AM
there's an excellent trig library around the internet

readme translated by google
Quote
Author: Gregory Cherevko
http://www.elecran.com.ua/
===========================
No liability for the use of these texts and the possible errors the authors did not carry.

General comments
functions are written in AutoLisp
All calculations are made by mathematical methods (vector algebra, analytic geometry) without using auxiliary AutoCAD entities and their analysis.
Global variables
Many library functions refer to two global variables
The variable $ P000 has the value '(0.0 0.0 0.0)
$ Dopusk has a value of 0.00001 - contains the error value is used for various comparisons (such as coordinates of points). He just needed to cope with the accumulated error in the calculations.
To initialize variables in the start of your program to insert the line
(Setq $ P000 '(0.0 0.0 0.0)
$ Dopusk 0.00001
)

Naming of variables, parameters
In the parameters of these functions are frequently used variable names.
P, P1, P2, P3 .... - Points
Pc - the central point of an arc or a circle
L, Lx, Ly, Lz - length
Wekt, Wekt1, Wekt2, WektX, WektY, WektZ, W, W1, W2-vector (the list of 3 numbers)
WNorm - normal vector. In terms of AutoCAD it comes to squeezing the direction vector, which all primitives stored under 210 associative code.
Ang - angle
R, R1, R2 - radius
================================================== ====================
Calculations of the arcs
 
1. Distance from a point in the plane of the arc to arc (1.zip)
2. Calculating the arc length (2.zip)
3. Calculation of the central angle of arc (3.zip)
4. Computation of the mid-point arc (4.zip)
5. Calculation of the center of the arc (the arc is defined by 2 points and the direction
tangent to the 1-th point) (5.zip)

Analysis functions belonging and intersection elements
 
6. Accessory points on the line, set point and the vector (15.zip)
7. Affiliation point interval (16.zip)
8. Affiliation point arc (all points in the same plane!) (17.zip)
9. Affiliation point arc (points in different planes!) (18.zip)
10. Affiliation arc arc (19.zip)

Function calculating the intersection of objects in space
 
11. The intersection of 2 circles given center and radius,
coplanar (10.zip)
12. The intersection of 2 circles given center and radius,
located in a given plane (11.zip)
13. Point of intersection of the line and plane (12.zip)
14. Point of intersection of the circle with the plane (13.zip)
15. Calculation of the intersection line of planes (14.zip)
16. Intersection of line and circle, lying in one plane (8.zip)
17. Intersection of line and circle, randomly located (9.zip)

General purpose functions
 
18. Vector product of vectors (20.zip)
19. Vector normal to the plane. The plane defined by 3 points (21.zip)
20. Calculation of the unit vector (unit vector) (22.zip)
21. Reduction of the vector to the length of 1000 (long vector) (23.zip)
22. Point lying on the point P1 at a distance L in the direction of the point P2 (24.zip)
23. Point lying on P1 at a distance L along the vector Wekt (25.zip)
24. Point, offset by a 2-m vectors (26.zip)
25. The condition of orthogonality (27.zip)
26. The angle between the vectors (29.zip)
27. The angle between the vectors in a clockwise direction from the normal (30.zip)
28. Vector angle with respect to this part of the normal (31.zip)
29. The nearest point from a given point of the segment (32.zip)
30. The distance from the point to the segment (33.zip)
31. Rotate the point around the axis (34.zip)
32. Projection of a point on the line (line set-point vector) (35.zip)
33. Projection of a point on the line (line given two points) (36.zip)
34. Projection of a point on the plane (37.zip)
35. The distance between the planes (38.zip)

Function of spatial geometry
 
36. Calculation of the point of contact from the point of the circle (6.zip)
37. The calculation of the points of contact to the 2-m circles (7.zip)
================================================== =======================
Title: Re: Convert GEOMCAL functions to LISP
Post by: SOFITO_SOFT on March 05, 2011, 11:30:40 AM
there's an excellent trig library around the internet
readme translated by google
Quote
Author: Gregory Cherevko
http://www.elecran.com.ua/
===========================

Wonderful  :lol: :lol: :lol:
Thanks 
Greetings  :-)
Title: Re: Convert GEOMCAL functions to LISP
Post by: SOFITO_SOFT on March 05, 2011, 01:27:52 PM
Hello everyone
LIB Magnifica features ... very compact.
But I can not find a function that is called by some other function.
Can it be an oversight? or am I too dumb?
function that occurs is:3d_cosw1w2

I think it is the cosine of the angle formed by 2 3dvectors. :|
I think it might be as follows:

Code: [Select]
(defun 3d_cosw1w2 (P1 P2 /)
   (cos (3d_angw1w2 p1 p2))
)

Using other functions which are included 3d_angw1w2.
I hope not to screw up.
Greetings from Madrid and thanks again. :-)

 
Title: Re: Convert GEOMCAL functions to LISP
Post by: SOFITO_SOFT 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. :-)
Title: Re: Convert GEOMCAL functions to LISP
Post by: SOFITO_SOFT 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  :-)
Title: Re: Convert GEOMCAL functions to LISP
Post by: gschmidt 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)))
)


Title: Re: Convert GEOMCAL functions to LISP
Post by: gile 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)
  )
)
Title: Re: Convert GEOMCAL functions to LISP
Post by: gschmidt 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.
Title: Re: Convert GEOMCAL functions to LISP
Post by: SOFITO_SOFT 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.
 
Title: Re: Convert GEOMCAL functions to LISP
Post by: Kerry 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
Title: Re: Convert GEOMCAL functions to LISP
Post by: SOFITO_SOFT 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. :-)
Title: Re: Convert GEOMCAL functions to LISP
Post by: Kerry 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)
Title: Re: Convert GEOMCAL functions to LISP
Post by: SOFITO_SOFT 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. :-)
Title: Re: Convert GEOMCAL functions to LISP
Post by: Kerry 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 ?
Title: Re: Convert GEOMCAL functions to LISP
Post by: SOFITO_SOFT 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.  :-)
Title: Re: Convert GEOMCAL functions to LISP
Post by: Kerry 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


Title: Re: Convert GEOMCAL functions to LISP
Post by: Lee Mac 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
Title: Re: Convert GEOMCAL functions to LISP
Post by: Kerry 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)
Title: Re: Convert GEOMCAL functions to LISP
Post by: xiaxiang on March 07, 2011, 08:47:39 PM
there's an excellent trig library around the internet
readme translated by google
Quote
Author: Gregory Cherevko
http://www.elecran.com.ua/
===========================

Wonderful  :lol: :lol: :lol:
Thanks 
Greetings  :-)
Great!
Deep in love with it :angel:
Title: Re: Convert GEOMCAL functions to LISP
Post by: gschmidt 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)
  )
)
Title: Re: Convert GEOMCAL functions to LISP
Post by: gschmidt 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 :oops:

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)
  )
)
Title: Re: Convert GEOMCAL functions to LISP
Post by: gschmidt 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]
Title: Re: Convert GEOMCAL functions to LISP
Post by: gschmidt 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

Title: Re: Convert GEOMCAL functions to LISP
Post by: gile 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.
Title: Re: Convert GEOMCAL functions to LISP
Post by: ribarm 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
Title: Re: Convert GEOMCAL functions to LISP
Post by: gile 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 (http://www.theswamp.org/index.php?topic=18725.0).

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)))
Title: Re: Convert GEOMCAL functions to LISP
Post by: ribarm 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)))
Title: Re: Convert GEOMCAL functions to LISP
Post by: Lee Mac 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))
  )
)
Title: Re: Convert GEOMCAL functions to LISP
Post by: ribarm 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.
Thanks for your replies...
Title: Re: Convert GEOMCAL functions to LISP
Post by: Lee Mac on March 19, 2011, 10:57:28 AM
That is equivalent to my code  :?
Title: Re: Convert GEOMCAL functions to LISP
Post by: gschmidt 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.
Title: Re: Convert GEOMCAL functions to LISP
Post by: chlh_jd on April 04, 2011, 10:53:44 PM
Hi Landlord, Today have some time to read this  :-)
where's the download link from http://www.elecran.com.ua/ ?
Title: Re: Convert GEOMCAL functions to LISP
Post by: chlh_jd on April 04, 2011, 10:58:56 PM
to get point set center ,
Code: [Select]
(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
Code: [Select]
(defun midpts (lst)
  (mapcar (function (lambda (x) (/ x (length lst))))
 (apply 'mapcar
(cons '+
      (mapcar (function (lambda (y)
  (trans y 0 0)
)
      )
      lst
      )
)
 )
  )
)
Title: Re: Convert GEOMCAL functions to LISP
Post by: cadplayer on April 05, 2012, 07:17:55 AM
Which font need it to read

Автор: Григорий Черевков
http://www.elecran.com.ua/
===========================
Никакой ответственности за использование этих текстов и возможных ошибок авторы не несут.

Общие комментарии
функции написаны на языке AutoLisp
Все вычисления произведены математическими методами (векторная алгебра, аналитическая геометрия) без построения вспомогательных примитивов Автокада и их разбора.
Глобальные переменные
Многие функции библиотеки ссылаются на две глобальные переменные
Переменная $P000 имеет значение ‘(0.0 0.0 0.0)
$Dopusk имеет значение 0.00001 – содержит величину погрешности используемую при различных сравнениях (например координат точек). Он просто необходим для борьбы с накопленной погрешностью при вычислениях.
Для инициализации переменных в стартовую часть Вашей программы нужно вставить строки
(setq $P000 ‘(0.0 0.0 0.0)
$Dopusk 0.00001
)

Соглашения об именах переменных-параметров
В параметрах функций часто используются следующие имена переменных.
P, P1, P2,P3…. – точки
Pc – центральная точка дуги или окружности
L, Lx, Ly, Lz – длины
Wekt, Wekt1, Wekt2, WektX, WektY, WektZ, W, W1, W2 –вектора (список из 3-х чисел)
WNorm – вектор нормали. В терминах Автокада речь идет о векторе направления выдавливания, который у всех примитивов хранится под 210 ассоциативным кодом.
Ang – угол
R, R1, R2 - радиус
======================================================================
Рассчеты дуг
 
1. Расстояние от точки, лежащей в плоскости дуги до дуги (1.zip)
2. Рассчет длины дуги (2.zip)
3. Рассчет центрального угла дуги (3.zip)
4. Вычисление средней точки дуги (4.zip)
5. Расчет центра дуги (дуга задана 2-мя точками и направлением
касательной в 1-й точке) (5.zip)

Функции анализа принадлежности и пересечения элементов
 
6. Принадлежность точки прямой, заданной точкой и вектором (15.zip)
7. Принадлежность точки отрезку (16.zip)
8. Принадлежность точки дуге (все точки в одной плоскости!) (17.zip)
9. Принадлежность точки дуге (точки в разных плоскостях!) (18.zip)
10. Принадлежность дуги дуге (19.zip)

Функции расчета пересечений объектов в пространстве
 
11. Пересечение 2-х окружностей заданных центром и радиусом,
лежащих в одной плоскости (10.zip)
12. Пересечение 2-х окружностей заданных центром и радиусом,
расположенных в заданной плоскости (11.zip)
13. Точка пересечения прямой и плоскости (12.zip)
14. Точки пересечения окружности с плоскостью (13.zip)
15. Расчет линии пересечения плоскостей (14.zip)
16. Пересечение прямой и окружности, лежащих в одной плоскости (8.zip)
17. Пересечение прямой и окружности, произвольно расположенных (9.zip)

Функции общего назначения
 
18. Векторное произведение векторов (20.zip)
19. Вектор нормали к плоскости. Плоскость задана 3-мя точкам (21.zip)
20. Вычисление орта (единичного вектора) (22.zip)
21.  Приведение вектора к длине 1000 (длинному вектору) (23.zip)
22. Точка лежащая от точки P1 на расстоянии L в направлении точки P2 (24.zip)
23. Точка лежащая от P1 на расстоянии L по вектору Wekt (25.zip)
24. Точка, смещенная по 2-м векторам (26.zip)
25. Условие ортогональности векторов (27.zip)
26. Угол между векторами (29.zip)
27. Угол между векторами по часовой стрелке со стороны нормали (30.zip)
28. Вектор под углом относительно данного со стороны нормали (31.zip)
29. Ближайшая от заданной точки точка отрезка (32.zip)
30. Расстояние от точки до отрезка (33.zip)
31. Поворот точки вокруг оси (34.zip)
32. Проекция точки на прямую (прямая задана точкой и вектором) (35.zip)
33. Проекция точки на прямую (прямая задана двумя точками) (36.zip)
34. Проекция точки на плоскость (37.zip)
35.  Расстояние между плоскостями (38.zip)

Функции пространственной геометрии
 
36. Расчет точки касания из точки к окружности (6.zip)
37. Расчет точек касания к 2-м окружностям (7.zip)
=========================================================================


 
Title: Re: Convert GEOMCAL functions to LISP
Post by: VovKa on April 05, 2012, 07:37:15 AM
Which font need it to read
not font but codepage
it's Cyrillic Windows-1251
Title: Re: Convert GEOMCAL functions to LISP
Post by: cadplayer on April 05, 2012, 09:54:26 AM
thanks. Have a nice WE
Title: Re: Convert GEOMCAL functions to LISP
Post by: scorpion76 on July 31, 2018, 12:05:33 PM
Here is look like treasure. :idiot2: