Jump to content

detect 90 degree corners


samifox

Recommended Posts

hi

a few years ago Lee Mac posted a simple mathematic function to easily detect 90-degree corners in a polyline. 

 

does anybody know?

 

Thanks

Shay

Link to comment
Share on other sites

Hi,

Try this one:

(defun angle90 (p1 p2 p3)
  (vl-some '(lambda (ang) (equal (abs (- (angle p1 p2) (angle p2 p3))) ang 1e-4))
            (list (* pi 0.5) (* pi 1.5) (+ pi pi))
    )
  )

(defun c:test ( / 1p 2p 3p )
  (and (setq 1p (getpoint "\n1st point :"))
       (setq 2p (getpoint "\n2nd point :" 1p))
       (setq 3p (getpoint "\n3rd point :" 2p))
       (alert (strcat "Angle is " (if (angle90 1p 2p 3p) "" "NOT") "equal to 90 Deg.")))         
  (princ))

 

Link to comment
Share on other sites

49 minutes ago, Tharwat said:

Hi,

Try this one:


(defun angle90 (p1 p2 p3)
  (vl-some '(lambda (ang) (equal (abs (- (angle p1 p2) (angle p2 p3))) ang 1e-4))
            (list (* pi 0.5) (* pi 1.5) (+ pi pi))
    )
  )

(defun c:test ( / 1p 2p 3p )
  (and (setq 1p (getpoint "\n1st point :"))
       (setq 2p (getpoint "\n2nd point :" 1p))
       (setq 3p (getpoint "\n3rd point :" 2p))
       (alert (strcat "Angle is " (if (angle90 1p 2p 3p) "" "NOT") "equal to 90 Deg.")))         
  (princ))

 

 

Thank you sir

 

i remember much simpler approach (involve sin cos or tan)

 

PO i really like your plumbing app, there is no price thou)

Link to comment
Share on other sites

1 minute ago, samifox said:

Thank you sir

 

i remember much simpler approach (involve sin cos or tan)

 

PO i really like your plumbing app, there is no price thou)

 

You're welcome.

If you already installed my Drainage Program then just hit the button Activate to know the price and the activation process but you can message me for more info.

 

 

Link to comment
Share on other sites

On 10/11/2018 at 4:48 PM, ronjonp said:

Use Lee's code then maybe this?


(equal 0. (rem ang (/ pi 2.)) 1e-8)

 

This will also report True for 0 and pi.

Maybe

(equal (cos ang) 0 1e-8)

For 3d polylines or rotated 2d polylines, the angle in p2, formed by 3 points p1, p2 and p3, is 90deg if the dot product of the vectors p2-p1 and p2-p3 is 0.0.

;dot product
(defun uxv (u v) (apply '+ (mapcar '* u v)))

(setq
  u (mapcar '- p1 p2)
  v (mapcar '- p3 p2)
)

(equal 0.0 (uxv u v) 1e-8)

 

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