Jump to content

lISP ANGLE MEASUREMENT IN AUTOCAD 3D


CongVenh

Recommended Posts

Hello everybody!
I want to measure the angle between a straight line and a plane (Do not use the Dist command), if the results can be exported to Excel, the better. As shown in the attached image I want the result of angle A and angle B (In minutes) between line MN and plane XOY.
Thank you very much.

Capture.PNG

Link to comment
Share on other sites

Like this?

(defun c:pp()
  (setq p1 (cdr (assoc 10 (setq el (entget (car (entsel "Select line   \n "))))))
	p2 (cdr (assoc 11 el))
	p3 (list (car p1) (cadr p1) (caddr p2))
	ang1 (atan (distance p1 p3) (distance p2 p3))
	ang2 (angle p3 p2)
	toMin (* 60 (/ 180.0 PI)))
  (strcat  (rtos (* ang1 toMin)) " min  /  " (rtos (* ang2 toMin)) " min")  
  )

 

  • Like 1
Link to comment
Share on other sites

On 11/17/2023 at 12:19 PM, fuccaro said:

Like this?

(defun c:pp()
  (setq p1 (cdr (assoc 10 (setq el (entget (car (entsel "Select line   \n "))))))
	p2 (cdr (assoc 11 el))
	p3 (list (car p1) (cadr p1) (caddr p2))
	ang1 (atan (distance p1 p3) (distance p2 p3))
	ang2 (angle p3 p2)
	toMin (* 60 (/ 180.0 PI)))
  (strcat  (rtos (* ang1 toMin)) " min  /  " (rtos (* ang2 toMin)) " min")  
  )

 

THANK YOU FOR HELP ME. BUT THE RESULT IS ERROR, PLEASE CHECK IT!Capture.thumb.PNG.87a92c1a94f2f1731b1e5d7e320ddbd6.PNG

Edited by fuccaro
deleting redundant images
Link to comment
Share on other sites

4 hours ago, BIGAL said:

Did you look for the mathematical answer ? Formulas with regards to planes. Then it could be converted to lisp.

 

4 hours ago, BIGAL said:

Did you look for the mathematical answer ? Formulas with regards to planes. Then it could be converted to lisp.

 

Hello. I want lisp to replace the DIST command in Autocad. Instead of reading the results from the DIST command, I want the angle measurement results (Angle A and Angle B as shown in the illustration) to be exported to excel or printed to the screen.

Link to comment
Share on other sites

Something like this :

 

(defun c:dii ( / ftoa x1 y1 z1 x2 y2 z2 x1w y1w z1w x2w y2w z2w x1o y1o z1o x2o y2o z2o p1 p2 d ducs docs dwcs dx dy dz v dxw dyw dzw w dxo dyo dzo ax vprim vprimd axy ocs stringid1 stringid1w stringid1o stringid2 stringid2w stringid2o string1 string2 string3 string4 string5 string6 string7 string8 string9 string10 string11 string12 string13 string14 string15 alertstring )

  (defun ftoa ( n / m a s b )
    (if (numberp n)
      (progn
        (setq m (fix ((if (< n 0) - +) n 1e-8)))
        (setq a (abs (- n m)))
        (setq m (itoa m))
        (setq s "")
        (while (and (not (equal a 0.0 1e-6)) (setq b (fix (* a 10.0))))
          (setq s (strcat s (itoa b)))
          (setq a (- (* a 10.0) b))
        )
        (if (= (type n) 'int)
          m
          (if (= s "")
            m
            (if (and (= m "0") (< n 0))
              (strcat "-" m "." s)
              (strcat m "." s)
            )
          )
        )
      )
    )
  )

  (while (not p1) (setq p1 (getpoint "\nPick or specify start point : ")))
  (while (not p2) (setq p2 (getpoint p1 "\nPick or specify end point : ")))
  (setq d (distance p1 p2))
  (grdraw p1 p2 6 1)
  (setq dx (car (setq v (mapcar (function -) p2 p1))))
  (setq dy (cadr v))
  (setq ducs (sqrt (+ (* dx dx) (* dy dy))))
  (setq dz (caddr v))
  (setq ocs (trans (list 0.0 0.0 1.0) 1 0 t))
  (setq dxo (car (mapcar (function -) (trans p2 1 ocs) (trans p1 1 ocs))))
  (setq dyo (cadr (mapcar (function -) (trans p2 1 ocs) (trans p1 1 ocs))))
  (setq dzo (caddr (mapcar (function -) (trans p2 1 ocs) (trans p1 1 ocs))))
  (setq docs (sqrt (+ (* dxo dxo) (* dyo dyo))))
  (setq dxw (car (setq w (trans v 1 0))))
  (setq dyw (cadr w))
  (setq dzw (caddr w))
  (setq dwcs (sqrt (+ (* dxw dxw) (* dyw dyw))))
  (setq ax (cvunit (atan dy dx) "radians" "degrees"))
  (setq vprim (list (car v) (cadr v) 0.0))
  (setq vprimd (distance (list 0.0 0.0 0.0) vprim))
  (setq axy (cvunit (atan (caddr v) vprimd) "radians" "degrees"))
  (setq x1 (car p1)
       y1 (cadr p1)
       z1 (caddr p1)
  )
  (setq x2 (car p2)
       y2 (cadr p2)
       z2 (caddr p2)
  )
  (setq x1w (car (trans p1 1 0))
       y1w (cadr (trans p1 1 0))
       z1w (caddr (trans p1 1 0))
  )
  (setq x2w (car (trans p2 1 0))
       y2w (cadr (trans p2 1 0))
       z2w (caddr (trans p2 1 0))
  )
  (setq x1o (car (trans p1 1 ocs))
       y1o (cadr (trans p1 1 ocs))
       z1o (caddr (trans p1 1 ocs))
  )
  (setq x2o (car (trans p2 1 ocs))
       y2o (cadr (trans p2 1 ocs))
       z2o (caddr (trans p2 1 ocs))
  )

  (prompt "\n\nID pt1 in UCS : (")(princ (rtos x1 2 50))(prompt " ")(princ (rtos y1 2 50))(prompt " ")(princ (rtos z1 2 50))(prompt ")")
  (prompt "\nID pt1 in WCS : (")(princ (rtos x1w 2 50))(prompt " ")(princ (rtos y1w 2 50))(prompt " ")(princ (rtos z1w 2 50))(prompt ")")
  (prompt "\nID pt1 in OCS : (")(princ (rtos x1o 2 50))(prompt " ")(princ (rtos y1o 2 50))(prompt " ")(princ (rtos z1o 2 50))(prompt ")")
  (prompt "\n\nID pt2 in UCS : (")(princ (rtos x2 2 50))(prompt " ")(princ (rtos y2 2 50))(prompt " ")(princ (rtos z2 2 50))(prompt ")")
  (prompt "\nID pt2 in WCS : (")(princ (rtos x2w 2 50))(prompt " ")(princ (rtos y2w 2 50))(prompt " ")(princ (rtos z2w 2 50))(prompt ")")
  (prompt "\nID pt2 in OCS : (")(princ (rtos x2o 2 50))(prompt " ")(princ (rtos y2o 2 50))(prompt " ")(princ (rtos z2o 2 50))(prompt ")")
  (prompt "\n\nDistance 2D projection in UCS plane : ")(princ (rtos ducs 2 50))
  (prompt "\n\nDX in UCS : ")(princ (rtos dx 2 50))
  (prompt "\nDY in UCS : ")(princ (rtos dy 2 50))
  (prompt "\nDZ in UCS : ")(princ (rtos dz 2 50))
  (prompt "\n\nDistance 2D projection in WCS plane : ")(princ (rtos dwcs 2 50))
  (prompt "\n\nDX in WCS : ")(princ (rtos dxw 2 50))
  (prompt "\nDY in WCS : ")(princ (rtos dyw 2 50))
  (prompt "\nDZ in WCS : ")(princ (rtos dzw 2 50))
  (prompt "\n\nDistance 2D projection in OCS plane : ")(princ (rtos docs 2 50))
  (prompt "\n\nDX in OCS : ")(princ (rtos dxo 2 50))
  (prompt "\nDY in OCS : ")(princ (rtos dyo 2 50))
  (prompt "\nDZ in OCS : ")(princ (rtos dzo 2 50))
  (prompt "\n\nDistance 3D : ")(princ (ftoa d))
  (prompt "\n\nAngle around Z axis from X axis as 0.0 degree reference : ")(princ (ftoa ax))(prompt " degrees")
  (prompt "\nAngle of picked points vector to XY plane : ")(princ (ftoa axy))(prompt " degrees")
  (setq stringid1 (strcat "\nID pt1 in UCS : " (rtos x1 2 50) "," (rtos y1 2 50) "," (rtos z1 2 50)))
  (setq stringid1w (strcat "\nID pt1 in WCS : " (rtos x1w 2 50) "," (rtos y1w 2 50) "," (rtos z1w 2 50)))
  (setq stringid1o (strcat "\nID pt1 in OCS : " (rtos x1o 2 50) "," (rtos y1o 2 50) "," (rtos z1o 2 50)))
  (setq stringid2 (strcat "\n\nID pt2 in UCS : " (rtos x2 2 50) "," (rtos y2 2 50) "," (rtos z2 2 50)))
  (setq stringid2w (strcat "\nID pt2 in WCS : " (rtos x2w 2 50) "," (rtos y2w 2 50) "," (rtos z2w 2 50)))
  (setq stringid2o (strcat "\nID pt2 in OCS : " (rtos x2o 2 50) "," (rtos y2o 2 50) "," (rtos z2o 2 50)))
  (setq string1 (strcat "\n\nDistance 2D projection in UCS plane : " (rtos ducs 2 50)))
  (setq string2 (strcat "\n\nDX in UCS : " (rtos dx 2 50)))
  (setq string3 (strcat "\nDY in UCS : " (rtos dy 2 50)))
  (setq string4 (strcat "\nDZ in UCS : " (rtos dz 2 50)))
  (setq string5 (strcat "\n\nDistance 2D projection in WCS plane : " (rtos dwcs 2 50)))
  (setq string6 (strcat "\n\nDX in WCS : " (rtos dxw 2 50)))
  (setq string7 (strcat "\nDY in WCS : " (rtos dyw 2 50)))
  (setq string8 (strcat "\nDZ in WCS : " (rtos dzw 2 50)))
  (setq string9 (strcat "\n\nDistance 2D projection in OCS plane : " (rtos docs 2 50)))
  (setq string10 (strcat "\n\nDX in OCS : " (rtos dxo 2 50)))
  (setq string11 (strcat "\nDY in OCS : " (rtos dyo 2 50)))
  (setq string12 (strcat "\nDZ in OCS : " (rtos dzo 2 50)))
  (setq string13 (strcat "\n\nDistance 3D : " (ftoa d)))
  (setq string14 (strcat "\n\nAngle around Z axis from X axis as 0.0 degree reference : " (ftoa ax) " degrees"))
  (setq string15 (strcat "\nAngle of picked points vector to XY plane : " (ftoa axy) " degrees"))
  (setq alertstring (strcat stringid1 stringid1w stringid1o stringid2 stringid2w stringid2o string1 string2 string3 string4 string5 string6 string7 string8 string9 string10 string11 string12 string13 string14 string15))
  (alert alertstring)
  (princ)
)

 

HTH.

M.R.

  • Like 1
Link to comment
Share on other sites

1 hour ago, marko_ribar said:

Something like this :

 

(defun c:dii ( / ftoa x1 y1 z1 x2 y2 z2 x1w y1w z1w x2w y2w z2w x1o y1o z1o x2o y2o z2o p1 p2 d ducs docs dwcs dx dy dz v dxw dyw dzw w dxo dyo dzo ax vprim vprimd axy ocs stringid1 stringid1w stringid1o stringid2 stringid2w stringid2o string1 string2 string3 string4 string5 string6 string7 string8 string9 string10 string11 string12 string13 string14 string15 alertstring )

  (defun ftoa ( n / m a s b )
    (if (numberp n)
      (progn
        (setq m (fix ((if (< n 0) - +) n 1e-8)))
        (setq a (abs (- n m)))
        (setq m (itoa m))
        (setq s "")
        (while (and (not (equal a 0.0 1e-6)) (setq b (fix (* a 10.0))))
          (setq s (strcat s (itoa b)))
          (setq a (- (* a 10.0) b))
        )
        (if (= (type n) 'int)
          m
          (if (= s "")
            m
            (if (and (= m "0") (< n 0))
              (strcat "-" m "." s)
              (strcat m "." s)
            )
          )
        )
      )
    )
  )

  (while (not p1) (setq p1 (getpoint "\nPick or specify start point : ")))
  (while (not p2) (setq p2 (getpoint p1 "\nPick or specify end point : ")))
  (setq d (distance p1 p2))
  (grdraw p1 p2 6 1)
  (setq dx (car (setq v (mapcar (function -) p2 p1))))
  (setq dy (cadr v))
  (setq ducs (sqrt (+ (* dx dx) (* dy dy))))
  (setq dz (caddr v))
  (setq ocs (trans (list 0.0 0.0 1.0) 1 0 t))
  (setq dxo (car (mapcar (function -) (trans p2 1 ocs) (trans p1 1 ocs))))
  (setq dyo (cadr (mapcar (function -) (trans p2 1 ocs) (trans p1 1 ocs))))
  (setq dzo (caddr (mapcar (function -) (trans p2 1 ocs) (trans p1 1 ocs))))
  (setq docs (sqrt (+ (* dxo dxo) (* dyo dyo))))
  (setq dxw (car (setq w (trans v 1 0))))
  (setq dyw (cadr w))
  (setq dzw (caddr w))
  (setq dwcs (sqrt (+ (* dxw dxw) (* dyw dyw))))
  (setq ax (cvunit (atan dy dx) "radians" "degrees"))
  (setq vprim (list (car v) (cadr v) 0.0))
  (setq vprimd (distance (list 0.0 0.0 0.0) vprim))
  (setq axy (cvunit (atan (caddr v) vprimd) "radians" "degrees"))
  (setq x1 (car p1)
       y1 (cadr p1)
       z1 (caddr p1)
  )
  (setq x2 (car p2)
       y2 (cadr p2)
       z2 (caddr p2)
  )
  (setq x1w (car (trans p1 1 0))
       y1w (cadr (trans p1 1 0))
       z1w (caddr (trans p1 1 0))
  )
  (setq x2w (car (trans p2 1 0))
       y2w (cadr (trans p2 1 0))
       z2w (caddr (trans p2 1 0))
  )
  (setq x1o (car (trans p1 1 ocs))
       y1o (cadr (trans p1 1 ocs))
       z1o (caddr (trans p1 1 ocs))
  )
  (setq x2o (car (trans p2 1 ocs))
       y2o (cadr (trans p2 1 ocs))
       z2o (caddr (trans p2 1 ocs))
  )

  (prompt "\n\nID pt1 in UCS : (")(princ (rtos x1 2 50))(prompt " ")(princ (rtos y1 2 50))(prompt " ")(princ (rtos z1 2 50))(prompt ")")
  (prompt "\nID pt1 in WCS : (")(princ (rtos x1w 2 50))(prompt " ")(princ (rtos y1w 2 50))(prompt " ")(princ (rtos z1w 2 50))(prompt ")")
  (prompt "\nID pt1 in OCS : (")(princ (rtos x1o 2 50))(prompt " ")(princ (rtos y1o 2 50))(prompt " ")(princ (rtos z1o 2 50))(prompt ")")
  (prompt "\n\nID pt2 in UCS : (")(princ (rtos x2 2 50))(prompt " ")(princ (rtos y2 2 50))(prompt " ")(princ (rtos z2 2 50))(prompt ")")
  (prompt "\nID pt2 in WCS : (")(princ (rtos x2w 2 50))(prompt " ")(princ (rtos y2w 2 50))(prompt " ")(princ (rtos z2w 2 50))(prompt ")")
  (prompt "\nID pt2 in OCS : (")(princ (rtos x2o 2 50))(prompt " ")(princ (rtos y2o 2 50))(prompt " ")(princ (rtos z2o 2 50))(prompt ")")
  (prompt "\n\nDistance 2D projection in UCS plane : ")(princ (rtos ducs 2 50))
  (prompt "\n\nDX in UCS : ")(princ (rtos dx 2 50))
  (prompt "\nDY in UCS : ")(princ (rtos dy 2 50))
  (prompt "\nDZ in UCS : ")(princ (rtos dz 2 50))
  (prompt "\n\nDistance 2D projection in WCS plane : ")(princ (rtos dwcs 2 50))
  (prompt "\n\nDX in WCS : ")(princ (rtos dxw 2 50))
  (prompt "\nDY in WCS : ")(princ (rtos dyw 2 50))
  (prompt "\nDZ in WCS : ")(princ (rtos dzw 2 50))
  (prompt "\n\nDistance 2D projection in OCS plane : ")(princ (rtos docs 2 50))
  (prompt "\n\nDX in OCS : ")(princ (rtos dxo 2 50))
  (prompt "\nDY in OCS : ")(princ (rtos dyo 2 50))
  (prompt "\nDZ in OCS : ")(princ (rtos dzo 2 50))
  (prompt "\n\nDistance 3D : ")(princ (ftoa d))
  (prompt "\n\nAngle around Z axis from X axis as 0.0 degree reference : ")(princ (ftoa ax))(prompt " degrees")
  (prompt "\nAngle of picked points vector to XY plane : ")(princ (ftoa axy))(prompt " degrees")
  (setq stringid1 (strcat "\nID pt1 in UCS : " (rtos x1 2 50) "," (rtos y1 2 50) "," (rtos z1 2 50)))
  (setq stringid1w (strcat "\nID pt1 in WCS : " (rtos x1w 2 50) "," (rtos y1w 2 50) "," (rtos z1w 2 50)))
  (setq stringid1o (strcat "\nID pt1 in OCS : " (rtos x1o 2 50) "," (rtos y1o 2 50) "," (rtos z1o 2 50)))
  (setq stringid2 (strcat "\n\nID pt2 in UCS : " (rtos x2 2 50) "," (rtos y2 2 50) "," (rtos z2 2 50)))
  (setq stringid2w (strcat "\nID pt2 in WCS : " (rtos x2w 2 50) "," (rtos y2w 2 50) "," (rtos z2w 2 50)))
  (setq stringid2o (strcat "\nID pt2 in OCS : " (rtos x2o 2 50) "," (rtos y2o 2 50) "," (rtos z2o 2 50)))
  (setq string1 (strcat "\n\nDistance 2D projection in UCS plane : " (rtos ducs 2 50)))
  (setq string2 (strcat "\n\nDX in UCS : " (rtos dx 2 50)))
  (setq string3 (strcat "\nDY in UCS : " (rtos dy 2 50)))
  (setq string4 (strcat "\nDZ in UCS : " (rtos dz 2 50)))
  (setq string5 (strcat "\n\nDistance 2D projection in WCS plane : " (rtos dwcs 2 50)))
  (setq string6 (strcat "\n\nDX in WCS : " (rtos dxw 2 50)))
  (setq string7 (strcat "\nDY in WCS : " (rtos dyw 2 50)))
  (setq string8 (strcat "\nDZ in WCS : " (rtos dzw 2 50)))
  (setq string9 (strcat "\n\nDistance 2D projection in OCS plane : " (rtos docs 2 50)))
  (setq string10 (strcat "\n\nDX in OCS : " (rtos dxo 2 50)))
  (setq string11 (strcat "\nDY in OCS : " (rtos dyo 2 50)))
  (setq string12 (strcat "\nDZ in OCS : " (rtos dzo 2 50)))
  (setq string13 (strcat "\n\nDistance 3D : " (ftoa d)))
  (setq string14 (strcat "\n\nAngle around Z axis from X axis as 0.0 degree reference : " (ftoa ax) " degrees"))
  (setq string15 (strcat "\nAngle of picked points vector to XY plane : " (ftoa axy) " degrees"))
  (setq alertstring (strcat stringid1 stringid1w stringid1o stringid2 stringid2w stringid2o string1 string2 string3 string4 string5 string6 string7 string8 string9 string10 string11 string12 string13 string14 string15))
  (alert alertstring)
  (princ)
)

 

HTH.

M.R.

Thank you very much. But the results shown above cannot be recorded on Autocad, so the effect is the same as the Dist command. Can you help me export that result to Excel or convert it into a text object on the drawing, it will be more convenient for me to process.

Link to comment
Share on other sites

Or this can help you?

(defun c:q_ang ( / px p1 p2 msg l_pt l_d p ang a_base a_dir)
  (initget 9)
  (setq px (getpoint "\nPoint at the vertex: ") p1 px p2 px msg '("p1" "\nFirst point: " "p2" "\nSecond point: "))
  (foreach n (list p1 p2)
    (while (equal px n)
      (initget 9)
      (setq n (getpoint px (cadr msg)))
      (if (equal px n)
        (princ "\nThe point is confound at the vertex!")
      )
    )
    (set (read (car msg)) n)
    (setq msg (cddr msg))
  )
  (setq
    l_pt (mapcar '(lambda (x) (list (car x) (cadr x))) (list px p1 p2))
    l_d (mapcar 'distance l_pt (append (cdr l_pt) (list (car l_pt))))
    p (/ (apply '+ l_d) 2.0)
    a_base (getvar "ANGBASE")
    a_dir (getvar "ANGDIR")
  )
  (if (zerop (* p (- p (cadr l_d))))
    (setq ang pi)
    (setq ang (* (atan (sqrt (/ (* (- p (car l_d)) (- p (caddr l_d))) (* p (- p (cadr l_d)))))) 2.0))
  )
  (setvar "ANGBASE" 0)
  (setvar "ANGDIR" 0)
  (alert
    (strcat
      "Angle expressed in terms of active units"
      "\nAngle: <" (angtos ang (getvar "AUNITS") (getvar "AUPREC")) ">"
      "\nComplementary angle at " (angtos pi (getvar "AUNITS") 0) ": <" (angtos (- pi ang) (getvar "AUNITS") (getvar "AUPREC"))">"
    )
  )
  (print (angtos ang (getvar "AUNITS") (getvar "AUPREC")))
  (setvar "ANGBASE" a_base)
  (setvar "ANGDIR" a_dir)
  (prin1)
)

 

Link to comment
Share on other sites

Given points O, M, and N, this will calculate the angles A and B and output them as text position at point O.

(defun c:angs ( / ptO ptM ptN uNM uNO A B)
(setq ptO (getpoint "\nPick point O: ")
      ptM (getpoint "\nPick point M: ")
      ptN (getpoint "\nPick point N: ")
      uNM (unitvec (mapcar '- ptM ptN))
      uNO (unitvec (mapcar '- ptO ptN))
      A	  (acos (dot '(-1 0 0) uNO))
      B	  (acos (dot uNM uNO))
)
  (princ "\n Angle A = ")
  (princ (rad2deg A))
  (princ "\n Angle B = ")
  (princ (rad2deg B))
  (princ)
(setq d 0.3) ; offset in y for text  
(setq ptA (mapcar '- ptO (list 0 d 0))
      ptB (mapcar '- ptO (list 0 (* 2 d) 0))
) 
(command "_text" "_non" ptA "" 0 (strcat "A = " (angtos A)) )  
(command "_text" "_non" ptB "" 0 (strcat "B = " (angtos B)) )  
)
;;; Compute the dot product of 2 vectors a and b
(defun dot (a b / d)
  (setq d (mapcar '* a b))
  (setq d (+ (nth 0 d) (nth 1 d) (nth 2 d)))
)					;end of dot
; compute unit vector of v
(defun unitvec (v / d)
  (setq	d	(distance '(0 0 0) v)
	d	(mapcar '/ v (list d d d))
  )
)
;; ArcCosine  -  Lee Mac
;; Args: -1 <= x <= 1
(defun acos (x)
  (if (<= -1.0 x 1.0)
    (atan (sqrt (- 1.0 (* x x))) x)
  )
)
;; radians to degrees
(defun rad2deg (angrad / d)
  (setq d (/ (* angrad 180.) pi))
)

 

Link to comment
Share on other sites

My program returns the angles A and B. The results are converted to minutes, as requested in the first post. I got it wrong?!

Concerning the export: do you wish to use the program on more lines, and get all the results in a single file? Or maybe the program should generate a new file (containing just two values) at each use?

Link to comment
Share on other sites

" if the results can be exported to Excel"

 

Yes can be done look here for "Alan Excel Library.lsp" or GETEXCEL.lsp they are both example code of functions that can be used for a solution.

Link to comment
Share on other sites

3 hours ago, fuccaro said:

My program returns the angles A and B. The results are converted to minutes, as requested in the first post. I got it wrong?!

Concerning the export: do you wish to use the program on more lines, and get all the results in a single file? Or maybe the program should generate a new file (containing just two values) at each use?

Hello Fuccaro. I only need 2 values A and B for 1 use

Link to comment
Share on other sites

And just this?

(defun C:ID-Angle ( / pt_o pt_f l_var dxf_11 ang ang_z)
  (initget 8)
  (setq pt_o (getpoint "\nFirst point: "))
  (if (null pt_o) (setq pt_o (getvar "lastpoint")))
  (cond
    (pt_o
      (initget 41)
      (setq pt_f (getpoint pt_o "\nSecond point: "))
      (cond
        ((and pt_f (null (equal pt_f pt_o 1E-13)))
          (setq
            l_var (mapcar 'getvar '("ANGBASE" "ANGDIR"))
            dxf_11
            (trans
              (mapcar
                '(lambda (x / ) (/ x (distance (trans pt_o 1 0) (trans pt_f 1 0))))
                (mapcar '- (trans pt_f 1 0) (trans pt_o 1 0))
              )
              0 1 T
            )
          )
          (if (zerop (car dxf_11))
            (setq ang "infinite")
            (setq ang (angtos (atan (/ (cadr dxf_11) (car dxf_11))) 1 2))
          )
          (if (= (caddr dxf_11) 1.0)
            (setq ang_z "infinite")
            (if (zerop (caddr dxf_11))
              (setq ang_z (angtos 0.0 1 2))
              (setq ang_z (angtos (atan (sqrt (/ 1.0 (- (/ 1.0 (* (caddr dxf_11) (caddr dxf_11))) 1.0)))) 1 2))
            )
          )
          (prompt (strcat "\nAngle in the XY plane = " ang " - Angle with the XY plane = " ang_z))
          (alert (strcat "Angle in the XY plane = " ang " - Angle with the XY plane = " ang_z))
          (mapcar 'setvar '("ANGBASE" "ANGDIR") l_var)
        )
        (T (princ "\nThe points are confused"))
      )
    )
  )
  (prin1)
)

 

Edited by Tsuky
Link to comment
Share on other sites

CongVenh

I still can't see the problem with the lisp I posted. Can you write me what it returns my lisp for a given line, and what return do you expect?

Link to comment
Share on other sites

@fuccaro  Per my test, your program calculates the correct angles and outputs the results in minutes as requested (I missed the "minutes" requirement in my code).  I think it should output the supplementary angle if the calculation is greater than 10800  (number of minutes in 180°). I'm wondering if the OP really wanted the angles in degrees-decimal minutes.

Link to comment
Share on other sites

14 hours ago, fuccaro said:

CongVenh

I still can't see the problem with the lisp I posted. Can you write me what it returns my lisp for a given line, and what return do you expect?

HI FUCCARO!

YOU SEE THE ATTACHED DRAWING. THE RESULTS FROM AUTOCAD'S DIST COMMAND AND FROM YOUR LISP ARE DIFFERENT. I DON'T UNDERSTAND THE CAUSE

DO GOC.dwg

Link to comment
Share on other sites

@CongVenh you asked for the angle in minutes and that is what @fuccaro gave you! As I noted previously, did you really want degrees, minutes and maybe seconds? Please be more specific about what you want. For example, do you want degrees and minutes with the minutes value rounded  and? seconds not included

Link to comment
Share on other sites

Thanks, lrm!

That's exactly my point. Your angle A is 17deg and 41min, or transformed in minutes only it is 1061 minutes.

On 11/17/2023 at 4:27 AM, CongVenh said:

 I want the result of angle A and angle B (In minutes)

 

 

Link to comment
Share on other sites

7 minutes ago, fuccaro said:

Thanks, lrm!

That's exactly my point. Your angle A is 17deg and 41min, or transformed in minutes only it is 1061 minutes.

 

 

7 minutes ago, fuccaro said:

Thanks, lrm!

That's exactly my point. Your angle A is 17deg and 41min, or transformed in minutes only it is 1061 minutes.

 

Thank you very much. But that result is not suitable for my work. Continue using the dist command (°⌣°) 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...