# detect 90 degree corners

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

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

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

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

##### Share on other sites

maybe google 'visual lisp angle between vertices'

##### Share on other sites

Use Lee's code then maybe this?

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

##### Share on other sites
16 hours ago, ronjonp said:
```
(equal 0. (rem ang (/ pi 2.)) 1e-8)﻿﻿```

THamks

##### Share on other sites
6 hours ago, samifox said:

THamks

You're welcome

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

##### Share on other sites
2 minutes ago, Stefan BMR said:

This will also report True for 0 and pi.

Oops

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.