Jump to content

help to correct routine that creates closed polygon by entering 2 measurements


cyberactive

Recommended Posts

 Hello, I have a routine but it fails when entering the last measurement, what it does is create a closed polygon by clicking on a base point, then it asks me to enter the front side and then returns to the base point to enter the side, but when drawing i

 

(defun c:acin (/ foo _dist p1 p2 p3 ang)
  (defun foo (l)
    (entmake
      (append '((0 . "LWPOLYLINE") (100 . "AcDbEntity") (100 . "AcDbPolyline") (90 . 4) (70 . 129))
              (mapcar (function (lambda (p) (cons 10 (reverse (cdr (reverse (trans p 1 0))))))) l)
      )
    )
  )

  (defun _dist (a b) (distance (list (car a) (cadr a)) (list (car b) (cadr b))))

  (if (setq p1 (getpoint "\nPica un punto base: "))
      (progn
        (setq p2 (getpoint p1 "\nIngresa la medida del frente: "))
        (not (grdraw p1 p2 3 1))
        
        (setq p3 (getpoint p1 "\nIngresa la medida del lado desde el punto base: "))
        (if (vl-consp p3)
            (foo (list p1 p2 p3 (polar p3 (angle p2 p1) (_dist p1 p2))))
          (if (eq (type p3) 'STR)
              (progn
                (setq ang (cond
                            ((eq p3 "I") (+ (/ pi 2.) (angle p2 p1)))
                            ((eq p3 "D") (+ (* pi 1.5) (angle p2 p1)))
                          ))
                (setq p3 (polar p1 ang (getreal "\nIngresa la medida del lado desde el punto base: ")))
                (foo (list p1 p2 p3 (polar p3 (angle p2 p1) (_dist p1 p2))))
              )
          )
        )
      )
  )
  (redraw) 
  (princ)
)

 

Link to comment
Share on other sites

Its seems to be working for me but the rectangle is  a little lopsided.

 

image.png.327bab695c27f2803e56e26a6cfe78a6.png

 

(getpoint will only return a list so this if statement is only going to run foo.

 

(defun c:acin (/ foo _dist p1 p2 p3 ang)
  (defun foo (l)
    (entmake
      (append '((0 . "LWPOLYLINE") (100 . "AcDbEntity") (100 . "AcDbPolyline") (90 . 4) (70 . 129))
              (mapcar (function (lambda (p) (cons 10 (reverse (cdr (reverse (trans p 1 0))))))) l)
      )
    )
  )
  (defun _dist (a b) (distance (list (car a) (cadr a)) (list (car b) (cadr b))))
  (setq p1 (getpoint "\nPica un punto base: "))
  (setq p2 (getpoint p1 "\nIngresa la medida del frente: "))
  (not (grdraw p1 p2 3 1))
  (setq p3 (getpoint p1 "\nIngresa la medida del lado desde el punto base: "))
  (if (vl-consp p3)
    (foo (list p1 p2 p3 (polar p3 (angle p2 p1) (_dist p1 p2)))) ;si p3 es una lista 
    (if (eq (type p3) 'STR) ;si p3 no es una lista, ejecute esto
      (progn
        (setq ang
          (cond
            ((eq p3 "I") (+ (/ pi 2.) (angle p2 p1)))
            ((eq p3 "D") (+ (* pi 1.5) (angle p2 p1)))
          )
        )
        (setq p3 (polar p1 ang (getreal "\nIngresa la medida del lado desde el punto base: ")))
        (foo (list p1 p2 p3 (polar p3 (angle p2 p1) (_dist p1 p2))))
      )
    )
  )
  (redraw)
  (princ)
)

 

 

 

 

Link to comment
Share on other sites

 

The problem is when I enter the second data it takes the final vertex and is very inclined

 

Link to comment
Share on other sites

calculating the midpoint of p2 and p3

 

image.png.e70beb1bd3e63f14739998440ee76e37.png


 

add this after P3
(setq mpt (mapcar '/ (mapcar '+ P2 P3) '(2 2 2)))


change foo
(foo (list p1 p2 (polar p1 (angle p1 mpt) (* (_dist p1 mpt) 2)) p3))

 

Edited by mhupp
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...