Jump to content

Recommended Posts

Posted

I have a lisp about nesting pattern for circular part as follows ,the code works like the first figure ,but I want it to be like in the second figure. I wonder how this code can be corrected?

 

 

(defun dtr (a)

(* pi (/ a 180.0))

)

(defun gpuser ()

(setq sp (getpoint "\nStart point of path: "))

(setq ep (getpoint "\nEnd point of path: "))

(setq hwidth (getdist "\nHalf width of path: " sp))

(setq trad (getdist "nRadius of tiles: " sp))

(setq tspac (getdist "\nSpacing between tiles: " sp))

(setq pangle (angle sp ep))

(setq plength (distance sp ep))

(setq width (* 2 hwidth))

(setq angp90 (+ pangle (dtr 90))) ; Path angle + 90 deg

(setq angm90 (- pangle (dtr 90))) ; Path angle - 90 deg

)

(defun drawout ()

(Command "pline"

(setq p (polar sp angm90 hwidth))

(setq p (polar p pangle plength))

(setq p (polar p angp90 width))

(polar p (+ pangle (dtr 180)) plength)

"close"

))

(defun drow (pd offset)

(setq pfirst (polar sp pangle pd))

(setq pctile (polar pfirst angp90 offset))

(setq pltile pctile)

(while (

(Command "circle" pltile trad)

(setq pltile

(polar pltile angp90 (+ tspac trad trad))))

(setq pltile (polar pctile angm90 (+ tspac trad trad)))

(while (

(Command "circle" pltile trad)

(setq pltile

(polar pltile angm90 (+ tspac trad trad)))))

(defun drawtiles ()

(setq pdist (+ trad tspac))

(setq off 0.0)

(while (

(drow pdist off)

(setq pdist

(+ pdist (* (+ tspac trad trad) (sin (dtr 60)))))

(if (= off 0.0)

(setq off (* (+ tspac trad trad) (cos (dtr 60))))

(setq off 0.0))))

(defun C:PATH ()

(gpuser)

(setq sblip (getvar "blipmode"))

(setq scmde (getvar "cmdecho"))

(setvar "blipmode" 0)

(setvar "cmdecho" 0)

(drawout)

(drawtiles)

(setvar "blipmode" sblip)

(setvar "cmdecho" scmde)

(princ)

)

 

mhemtg.png

 

 

 

28ajn04.png

 

 

 

 

Thanks in advance for your helps

Posted

Kaan , take a quick read about to include the codes in a tag codes from HERE .

 

What is the difference between the two figures ?

Posted

(defun dtr (a)
 (* pi (/ a 180.0))
 )
(defun gpuser ()
 (setq sp (getpoint "\nStart point of path: "))
 (setq ep (getpoint "\nEnd point of path: "))
 (setq hwidth (getdist "\nHalf width of path: " sp))
 (setq trad (getdist "nRadius of tiles: " sp))
 (setq tspac (getdist "\nSpacing between tiles: " sp))
 (setq pangle (angle sp ep))
 (setq plength (distance sp ep))
 (setq width (* 2 hwidth))
 (setq angp90 (+ pangle (dtr 90))) ; Path angle + 90 deg
 (setq angm90 (- pangle (dtr 90))) ; Path angle - 90 deg
 )
 (defun drawout ()
   (Command "pline"
     (setq p (polar sp angm90 hwidth))
     (setq p (polar p pangle plength))
     (setq p (polar p angp90 width))
     (polar p (+ pangle (dtr 180)) plength)
     "close"
     ))
 (defun drow (pd offset)
   (setq pfirst (polar sp pangle pd))
   (setq pctile (polar pfirst angp90 offset))
   (setq pltile pctile)
   (while (< (distance pfirst pltile) (- hwidth trad))
     (Command "circle" pltile trad)
     (setq pltile
     (polar pltile angp90 (+ tspac trad trad))))
   (setq pltile (polar pctile angm90 (+ tspac trad trad)))
   (while (< (distance pfirst pltile) (- hwidth trad))
     (Command "circle" pltile trad)
     (setq pltile
     (polar pltile angm90 (+ tspac trad trad)))))
   (defun drawtiles ()
     (setq pdist (+ trad tspac))
     (setq off 0.0)
     (while (<= pdist (- plength trad))
(drow pdist off)
(setq pdist
       (+ pdist (* (+ tspac trad trad) (sin (dtr 60)))))
(if (= off 0.0)
  (setq off (* (+ tspac trad trad) (cos (dtr 60))))
  (setq off 0.0))))
   (defun C:PATH ()
     (gpuser)
     (setq sblip (getvar "blipmode"))
     (setq scmde (getvar "cmdecho"))
     (setvar "blipmode" 0)
     (setvar "cmdecho" 0)
     (drawout)
     (drawtiles)
     (setvar "blipmode" sblip)
     (setvar "cmdecho" scmde)
     (princ)
     )

 

Thanks for the warning Tharwat. Drawing seems with angle on the screen the first figure, but I don't understand why drawing angle.

Posted
(defun gpuser ()
 (setq sp (getpoint "\nStart point of path: "))
 (setq ep (getpoint [highlight]sp[/highlight] "\nEnd point of path: "))
...

And turn on ORTHO ( F8 )

Posted (edited)

I have just wrote this quickie code and hope it would meet your needs :)

 

It's rectangular method .

 

 

(defun c:Test (/ p1 p2 p3 rd sp w h a b l1 l2 w1 h1 h p pt ang)
 ;; Author ; Tharwat Al Shoufi 15. Sep. 2013    ;;;
 (if
   (and
     (setq p1 (getpoint "\n Specify first point of Path :"))
     (setq p2 (getcorner "\n End point :" p1))
     (setq rd (getdist "\n Specify Radius of Tile [Circle] :"))
     (setq sp (getdist "\n Specify Spaceing between Tiles :"))
     (if (> (setq w (distance p1 (list (car p2) (cadr p1) 0.)))
            (* rd 2.)
         )
       t
       (progn
         (alert
           "Diameter of Tile is longer than the Width of Rectangle <!>"
         )
         nil
       )
     )
     (if (> (setq h (distance p1 (list (car p1) (cadr p2) 0.)))
            (* rd 2.)
         )
       t
       (progn
         (alert
           "Diameter of Tile is longer than the Height of Rectangle <!>"
         )
         nil
       )
     )
   )
    (progn
      (setq a   (apply 'min (mapcar 'car (list p1 p2)))
            b   (apply 'max (mapcar 'cadr (list p1 p2)))
            l1  (+ rd sp)
            w1  l1
            l2  (+ rd sp)
            h1  l2
            p   (list a b 0.)
            ang (angle p
                       (if (> (cadr p1) (cadr p2))
                         (list (car p2) (cadr p1) 0.)
                         (list (car p1) (cadr p2) 0.)
                       )
                )
            p   (polar (list a b 0.) (+ ang (* pi 1.5)) l1)
            p3  p
      )
      (repeat (fix (/ h (+ sp rd rd)))
        (repeat (fix (/ w (+ sp rd rd)))
          (setq pt (polar p3 ang l1)
                l1 (+ l1 (+ w1 rd))
          )
          (entmakex (list '(0 . "CIRCLE") (cons 40 rd) (cons 10 pt)))
        )
        (setq p3 (polar p (+ ang (* pi 1.5)) (+ rd l2))
              l2 (+ l2 (+ h1 rd))
              l1 w1
        )
      )
      (command "_.rectang" "_none" p1 "_none" p2)
    )
 )
 (princ)
)

Edited by Tharwat
Posted

Tharwat thanks for code, I tried that but, it didn't work.I think it's a problem about dimensions. I wonder if you have tried it?

Posted

It should work , but the way that I wrote the code is different than the one you posted earlier .

First you should pick a point and the second point should represent a rectangle and after that the radius of the circle [ tile ] and the space between the circles .

Posted

Although the radius of the circle is small, it gives alert.:unsure:

Posted
Although the radius of the circle is small, it gives alert.:unsure:

Correct , there was a small mistake with the smaller than operator , it is okay now I fix it .

 

Try it one more time please :)

Posted

Thanks Tharwat it is work. So how do I get into the rectangle them? That is, I want to appear the rectangle the outside of the shape.

Posted
Thanks Tharwat it is work. So how do I get into the rectangle them? That is, I want to appear the rectangle the outside of the shape.

 

You're welcome .

 

Rectangle added to the code .

Posted

Please edit your original post to include the Code in Code Tags.

  • 1 month later...
Posted

(defun dtr (a)
 (* pi (/ a 180.0))
 )
(defun gpuser ()
 (setq sp (getpoint "\nStart point of path: "))
 (setq ep (getpoint sp "\nEnd point of path: "))
 (setq hwidth (getdist "\nHalf width of path: " sp))
 (setq trad (getdist "nRadius of tiles: " sp))
 (setq tspac (getdist "\nSpacing between tiles: " sp))
 (setq pangle (angle sp ep))
 (setq plength (distance sp ep))
 (setq width (* 2 hwidth))
 (setq angp90 (+ pangle (dtr 90))) ; Path angle + 90 deg
 (setq angm90 (- pangle (dtr 90))) ; Path angle - 90 deg
 )
 (defun drawout ()
   (Command "pline"
     (setq p (polar sp angm90 hwidth))
     (setq p (polar p pangle plength))
     (setq p (polar p angp90 width))
     (polar p (+ pangle (dtr 180)) plength)
     "close"
     ))
 (defun drow (pd offset)
   (setq pfirst (polar sp pangle pd))
   (setq pctile (polar pfirst angp90 offset))
   (setq pltile pctile)
   (while (< (distance pfirst pltile) (- hwidth trad))
     (Command "circle" pltile trad)
     (setq pltile
     (polar pltile angp90 (+ tspac trad trad))))
   (setq pltile (polar pctile angm90 (+ tspac trad trad)))
   (while (< (distance pfirst pltile) (- hwidth trad))
     (Command "circle" pltile trad)
     (setq pltile
     (polar pltile angm90 (+ tspac trad trad)))))
   (defun drawtiles ()
     (setq pdist (+ trad tspac))
     (setq off 0.0)
     (while (<= pdist (- plength trad))
(drow pdist off)
(setq pdist
       (+ pdist (* (+ tspac trad trad) (sin (dtr 60)))))
(if (= off 0.0)
  (setq off (* (+ tspac trad trad) (cos (dtr 60))))
  (setq off 0.0))))
   (defun C:PATH ()
     (gpuser)
     (setq sblip (getvar "blipmode"))
     (setq scmde (getvar "cmdecho"))
     (setvar "blipmode" 0)
     (setvar "cmdecho" 0)
     (drawout)
     (drawtiles)
     (setvar "blipmode" sblip)
     (setvar "cmdecho" scmde)
     (princ)
     )

 

I wonder if this method can be applied in irregular shapes?

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