1. Login to Give a bone

## Almost Rectangle

In measuring operations, it often happens to measure rectangular objects (for example a road manhole) which however results almost rectangular.
Is there a lisp that transforms from an almost rectangle into a rectangle?
I wrote it, but I'm not sure if the algorithm is the best.
The best algorithm is the one that minimizes the error, mine doesn't.
Almost-Rectangle-Rid.Png

2. Login to Give a bone

## Re: Almost Rectangle

I don’t understand what you’re doing. How are you measuring? Do you mean drawing? You haven’t shown your code, so we can’t comment on it. But I would just throw a couple perpendicular constraints on it. Or use the rectangle command.

3. Login to Give a bone

## Re: Almost Rectangle

Originally Posted by Ed Jobe
I don’t understand what you’re doing ... use the rectangle command.
Rectangle command doesn’t suit.
It only draws a rectangle oriented as axis X and Y
I (and many others, I suppose) need to draw rectangles in every position.
Esample:
An iron manhole on the road: it is certainly rectangular, but the optical measure takes 4 points that are the vertices of an almost rectangle.
As I know that it is a rectangle I have to draw a perfect rectangle, so I must minimize the errors.
I wrote a lisp do to this, but I’m sure that it isn’t the best algorithm to minimize errors.
Later (few minutes) I'll post my lisp

- - - Updated - - -

Originally Posted by Ed Jobe
I don’t understand what you’re doing. How are you measuring? Do you mean drawing? You haven’t shown your code, so we can’t comment on it. But I would just throw a couple perpendicular constraints on it. Or use the rectangle command.
Thanks for the attention

4. Login to Give a bone

## Re: Almost Rectangle

Here is my code
Very simple
Draw an almost rectangle (four sides not exactly perpendicular) and run the ARec command.

5. Login to Give a bone

## Re: Almost Rectangle

I’m not at work today so I can’t help too much. What makes you unsatisfied with your results? What about placing a block using the coordinates and angle of a side?

6. Login to Give a bone

## Re: Almost Rectangle

This code will make your work much easier you can select as much as you want from the "Almost Rectangle"
Like if you have 100 or 1000 it will automate the work for you.

Best Regards.

HTML Code:
```;; -----------------------
;; ARec = Almost Rectangle
;; -----------------------

(defun pflaot (pl) (list (float (car pl)) (float (cadr pl))))

(defun make:lwpoly  (ptsList)
(setq *ModelSpace* (vla-get-ModelSpace doc))
(progn
(setq ptsList (apply 'append (mapcar 'pflaot ptsList)))
(setq arraySpace (vlax-make-safearray vlax-vbdouble (cons 0 (- (length ptsList) 1))))
(setq sArray (vlax-safearray-fill arraySpace ptsList))
(vlax-make-variant sArray)
)))
(vla-put-closed pline T)
pline
)

(defun Midda (q1 q2 / xmid ymid)
(setq xmid (/ (+ (nth 0 q1) (nth 0 q2)) 2))
(setq ymid (/ (+ (nth 1 q1) (nth 1 q2)) 2))
(list xmid ymid)
)
(defun rec:a (pobj  /)
(setq p1(car(pline:po pobj)))

(setq PX (Midda P1 P2))
(setq PY (Midda P3 P4))
(setq PP (Midda PX PY))
(setq AA (angle PX PY))
(setq DA (/ (+ (distance P1 P2) (distance P3 P4)) 4))
(setq DB (/ (+ (distance P1 P4) (distance P2 P3)) 4))
(setq TA1 (polar PP AA DB))
(setq TA2 (polar PP (+ AA PI) DB))
(setq AA (+ AA (/ PI 2)))
(setq Q1 (polar PX AA DA))
(setq Q2 (polar PX (+ AA PI) DA))
(setq Q3 (polar PY (+ AA PI) DA))
(setq Q4 (polar PY AA DA))

(make:lwpoly (list Q1 Q2 Q3 Q4))

)
(defun flout>list2d  (coords / coords coordpairs)
(while coords
(setq coordpairs (cons (list (car coords) (cadr coords)) coordpairs)
coords     (cddr coords))
)
(setq coordpairs (reverse coordpairs))
coordpairs
)

(defun po:list (ent prop / ent)
(setq crlp (vlax-get (vlax-ename->vla-object ent)   prop))
crlp
)

(defun pline:po (plobj)
(setq pol(flout>list2d(po:list plobj 'Coordinates)))
pol
)
;; -----------------------
(defun C:ARec (/ plnl)
(command-s "_undo" "_g")
(princ "Select a retangle/s:")
(setq ss (ssget  '((0 . "*LWPOLYLINE")(70 . 1))))

(setq ssl(sslength ss))
(setq n 0)
(repeat ssl

(setq pln (ssname ss n))
(if
(= (length(pline:po pln))4)
(setq plnl(append plnl (list pln)))
(princ)
)
(setq n (1+ n))
)
(mapcar (function(lambda (x)
(rec:a x)))
plnl)
(command-s "_undo" "_e")
(princ)
)
;; -----------------------

```

7. Login to Give a bone

## Re: Almost Rectangle

Originally Posted by Osama.Omari
This code will make your work much easier you can select as much as you want from the "Almost Rectangle"
Like if you have 100 or 1000 it will automate the work for you.
Thanks you very much.
It works.
I don't think I understand how it works, but it works.
In the next days I will try to understand the algorithm you used.

8. Login to Give a bone

## Re: Almost Rectangle

Originally Posted by rikferrari7739446
Rectangle command doesn’t suit.
It only draws a rectangle oriented as axis X and Y
I (and many others, I suppose) need to draw rectangles in every position.
I know others have answered your request for a routine, however, the rectangle command allows different rotation angles using the Rotation option within the command.

9. Login to Give a bone

## Re: Almost Rectangle

Originally Posted by Opie
I know others have answered your request for a routine, however, the rectangle command allows different rotation angles using the Rotation option within the command.
It's true, I have tried it now.
Thanks for the information.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•