Jump to content
samifox

detect 90 degree corners

Recommended Posts

samifox

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

Share this post


Link to post
Share on other sites
Tharwat

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

 

Share this post


Link to post
Share on other sites
samifox
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)

Share this post


Link to post
Share on other sites
Tharwat
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.

 

 

Share this post


Link to post
Share on other sites
ronjonp

Use Lee's code then maybe this?

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

 

Share this post


Link to post
Share on other sites
samifox
16 hours ago, ronjonp said:

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

 

THamks

Share this post


Link to post
Share on other sites
ronjonp
6 hours ago, samifox said:

THamks

You're welcome :)

Share this post


Link to post
Share on other sites
Stefan BMR
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)

 

Share this post


Link to post
Share on other sites
ronjonp
2 minutes ago, Stefan BMR said:

This will also report True for 0 and pi.

Oops 😳

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×