Jump to content

Recommended Posts

Posted

Еhis problem has already been discussed but I wanted to slightly alter it for myself. Now in these lines he takes a common point. And subtracted, starting from the middle (common point). How to make everything go from left to right. That is, the starting point, then the middle (bend point) and the end point. https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/calculate-angle-between-two-lines/td-p/803914 FILE ATTACHED

sclang_drju.lsp

Posted

Post a dwg or a image of what you want your request to me does not make much sense. I have some hor and ver scale routines which is what I think you want.

Posted
On 05/11/2020 at 06:03, BIGAL said:

Post a dwg or a image of what you want your request to me does not make much sense. I have some hor and ver scale routines which is what I think you want.

To get point 1,2,3 and get angle of point 2

image.thumb.png.19f37d940c52aee2c8d82ad5c1bdb56e.png

Posted

I'll translate it in a better language for you BIGAL, simply put:

 

Click three point 1, 2, and 3 and have the function return the inside angle formed by the points 123. I'll leave the rest to you 😉.

  • Like 1
Posted (edited)

For me pick corner get line angles,  internal angle done in lisp. Either lines or pline the latter more complicated. 

 

Need to get the y diff x diff and multiply by a  scale factor so return correct angle, for metric its easy 1000 / scale so question is your vertical scale metric or imperial.

 

If its a pline with multi segments then would need to do multi angles but only 1 pick.

 

Daniil need to post a sample dwg.

image.png.8b23bf280fc5f64ce910afbb75795429.png

 

Edited by BIGAL
Posted

Oh well... 

(defun c:test ( / p1 p2 p3)
    (and
	(setq p1 (getpoint "\nSpecify first point <exit>: "))
	(setq p2 (getpoint "\nSpecify second point <exit>: "))
	(setq p3 (getpoint "\nSpecify third point <exit>: "))
	(princ (strcat "\nInner angle formed: " (rtos (rtod (JH:InnerAngle p1 p2 p3)) 2 1) "°"))
	)
    (princ)
    )

(defun rtod (ang) (* 180 (/ ang pi)))

;; JH:InnerAngle --> Jonathan Handojo
;; Returns the smaller angle between three point p1 p2 p3
;; with p2 as the pivot, in radians.

(defun JH:InnerAngle (p1 p2 p3 / 2p ang)
    (setq ang (- (angle p2 p3) (angle p2 p1)) 2p (+ pi pi))
    (while (not (<= 0 ang 2p)) (if (< ang 0) (setq ang (+ ang 2p)) (setq ang (- ang 2p))))
    (if (> ang pi) (- 2p ang) ang)
    )

 

Posted
2 hours ago, Jonathan Handojo said:

Oh well... 


(defun c:test ( / p1 p2 p3)
    (and
	(setq p1 (getpoint "\nSpecify first point <exit>: "))
	(setq p2 (getpoint "\nSpecify second point <exit>: "))
	(setq p3 (getpoint "\nSpecify third point <exit>: "))
	(princ (strcat "\nInner angle formed: " (rtos (rtod (JH:InnerAngle p1 p2 p3)) 2 1) "°"))
	)
    (princ)
    )

(defun rtod (ang) (* 180 (/ ang pi)))

;; JH:InnerAngle --> Jonathan Handojo
;; Returns the smaller angle between three point p1 p2 p3
;; with p2 as the pivot, in radians.

(defun JH:InnerAngle (p1 p2 p3 / 2p ang)
    (setq ang (- (angle p2 p3) (angle p2 p1)) 2p (+ pi pi))
    (while (not (<= 0 ang 2p)) (if (< ang 0) (setq ang (+ ang 2p)) (setq ang (- ang 2p))))
    (if (> ang pi) (- 2p ang) ang)
    )

Thank you! Yes now this lisp almost works as desired but not scale the result that comes out. In the example, you can see how it is multiplied by 0.1

 

Posted

I don't get what the scale factor is supposed to mean. I merely assumed that you want to return the inside angle formed between 3 points. Can you elaborate further on how the calculation works?

Posted
38 minutes ago, Jonathan Handojo said:

I don't get what the scale factor is supposed to mean. I merely assumed that you want to return the inside angle formed between 3 points. Can you elaborate further on how the calculation works?

In this example you see this calculation. This is required for the longitudinal profile. When hor 1:500 and vert 1:50.

 

(setq pt2 (getpoint))
(setq ang1 (getangle pt2 "\nSelect angle: "))
(setq ang2 (getangle pt2 "\nSelect angle: "))
(setq ung1 (rtod (sclang ang1 0.1)))
(setq ung2 (rtod (sclang ang2 0.1)))
(setq ung (abs(- ung1 ung2)))
(princ "\nAngle on ")
(princ ung)
(princ)
)
(defun rtod (ang) ; rad to degree
(setq ang (* 180.0 (/ ang pi)))
)

Posted (edited)

Oh, I see... I thought the image you post was the plan view and was sloping in 3D going into the screen, but that was actually the side view of the drainage. My mistake.

 

(defun c:test ( / p1 p2 p3 hz vt dp)
    (and
	(setq p1 (getpoint "\nSpecify first point <exit>: "))
	(setq p2 (getpoint "\nSpecify second point <exit>: "))
	(setq p3 (getpoint "\nSpecify third point <exit>: "))
	(setq hz (getreal "\nSpecify horizontal scale <exit>: "))
	(setq vt (getreal "\nSpecify vertical scale <exit>: "))
	(setq dp (cond ((getreal "\nSpecify depth scale <1.0>: ")) (1.0)))
	(mapcar
	    '(lambda (x / dir)
		 (setq dir (mapcar '- (eval x) p1))
		 (set x (mapcar '(lambda (a b c) (+ a (* b c))) p1 dir (list hz vt dp)))
		 )
	    '(p2 p3)
	    )
	(princ (strcat "\nInner angle formed: " (rtos (rtod (JH:InnerAngle3D p1 p2 p3)) 2 1) "°"))
	)
    (princ)
    )

(defun rtod (ang) (* 180 (/ ang pi)))

;; JH:InnerAngle3D --> Jonathan Handojo
;; Returns the smaller angle between three point p1 p2 p3
;; with p2 as the pivot, in radians.
;; Adaptable with 3D points

(defun JH:InnerAngle3D (p1 p2 p3)
    (acos
	(/
	    (apply '+ (mapcar '* (mapcar '- p1 p2) (mapcar '- p3 p2)))
	    (* (distance p2 p1) (distance p2 p3))
	    )
	)
    )

;; ArcCosine  -  Lee Mac
;; Args: -1 <= x <= 1
 
(defun acos ( x )
    (if (<= -1.0 x 1.0)
        (atan (sqrt (- 1.0 (* x x))) x)
    )
)

 

This is adaptable in 3D, so in addition to the horizontal and vertical scale, you can also specify the depth scale too.

Edited by Jonathan Handojo
Posted

Good solution 3rd axis a good idea 

 

A typical dwg see the scales it is helpful when the OP post a true idea of what they want. "30 profiles with water pipe lines" water pipes have a limited number of off the shelf bends else custom bends generally for large pipes 375mm+

 

image.thumb.png.4019b081dc6acb88250bcd63db2af3c2.png

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...