See the top rated post in this thread. Click here

Results 1 to 9 of 9

Thread: Almost Rectangle

  1. #1
    Member
    Join Date
    2016-11
    Posts
    5
    Login to Give a bone
    0

    Default 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. #2
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,302
    Login to Give a bone
    0

    Default 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.
    C:> ED WORKING....

  3. #3
    Member
    Join Date
    2016-11
    Posts
    5
    Login to Give a bone
    0

    Default Re: Almost Rectangle

    Quote Originally Posted by Ed Jobe View Post
    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 - - -

    Quote Originally Posted by Ed Jobe View Post
    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. #4
    Member
    Join Date
    2016-11
    Posts
    5
    Login to Give a bone
    0

    Default Re: Almost Rectangle

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

  5. #5
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,302
    Login to Give a bone
    0

    Default 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?
    C:> ED WORKING....

  6. #6
    Member
    Join Date
    2016-05
    Posts
    17
    Login to Give a bone
    1

    Default 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
    ;; -----------------------
    
    (vl-load-com)
    
    (defun pflaot (pl) (list (float (car pl)) (float (cadr pl))))
    
    (defun make:lwpoly  (ptsList)
    (setq acadObj (vlax-get-acad-object))
    (setq doc (vla-get-ActiveDocument acadObj))
    (setq *ModelSpace* (vla-get-ModelSpace doc))
    (setq pline (vla-addLightweightPolyline *ModelSpace*
    (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 p2(cadr(pline:po pobj)))
    (setq p3(caddr(pline:po pobj)))
    (setq p4(cadddr(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. #7
    Member
    Join Date
    2016-11
    Posts
    5
    Login to Give a bone
    0

    Default Re: Almost Rectangle

    Quote Originally Posted by Osama.Omari View Post
    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. #8
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,057
    Login to Give a bone
    0

    Default Re: Almost Rectangle

    Quote Originally Posted by rikferrari7739446 View Post
    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.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  9. #9
    Member
    Join Date
    2016-11
    Posts
    5
    Login to Give a bone
    0

    Default Re: Almost Rectangle

    Quote Originally Posted by Opie View Post
    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.

Similar Threads

  1. Replies: 3
    Last Post: 2009-04-15, 07:30 PM
  2. Layer Manager Box graphics go "almost" blank
    By blong in forum AutoCAD Map 3D - General
    Replies: 3
    Last Post: 2005-01-28, 11:13 AM
  3. Almost too basic- text style + dimension styles-setup
    By sfickettj in forum ACA General
    Replies: 9
    Last Post: 2004-06-25, 02:16 PM
  4. Edited: Autodesk Almost Ready to Launch Revit 6.0!!!!!!
    By christopher.zoog51272 in forum Announcements
    Replies: 13
    Last Post: 2003-12-17, 06:38 AM

Posting Permissions

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