Author Topic: How to grdraw / grvecs a circle?  (Read 1062 times)

0 Members and 1 Guest are viewing this topic.

Peter2

  • Swamp Rat
  • Posts: 595
How to grdraw / grvecs a circle?
« on: February 10, 2020, 08:25:57 AM »
I have to "grdraw / grvecs" a (kind of ) circle, and at the moment I use grdraw to create a octogon. That's 99% good enough (also I could you a x^n gon ..), but nevertheless I would like to know: is there a simple way to grdraw a circle? I don't think so ....
Peter

AutoCAD Map 3D 2018 German (so some technical terms will be badly retranslated to English)
BricsCAD V19

roy_043

  • Water Moccasin
  • Posts: 1816
  • BricsCAD 18
Re: How to grdraw / grvecs a circle?
« Reply #1 on: February 10, 2020, 12:54:15 PM »
BricsCAD has the grarc function.

Stefan

  • Bull Frog
  • Posts: 238
Re: How to grdraw / grvecs a circle?
« Reply #2 on: February 11, 2020, 05:27:33 AM »
You can use entmod

Code - Auto/Visual Lisp: [Select]
  1. (setq c (entmakex '((0 . "CIRCLE") (10 0.0 0.0 0.0) (40 . 1.0))))
  2.  
  3.   (= (car (setq gr (grread T))) 5)
  4.   (entmod
  5.     (list
  6.       (cons -1 c)
  7.       (cons 10 (cadr gr))
  8.     )
  9.   )
  10. )

Peter2

  • Swamp Rat
  • Posts: 595
Re: How to grdraw / grvecs a circle?
« Reply #3 on: February 12, 2020, 03:08:28 AM »
Thanks Stefan
an interessting thing, but not what I need. But it shows the direction to use "entmake circle / delete circle" instead of grdraw.   
Peter

AutoCAD Map 3D 2018 German (so some technical terms will be badly retranslated to English)
BricsCAD V19

Augusto

  • Newt
  • Posts: 47
Re: How to grdraw / grvecs a circle?
« Reply #4 on: February 12, 2020, 05:21:16 AM »
For study purposes, I used some functions to make an arc using grvecs.
maybe that can help you to have other ideas.  :idea:

https://www.theswamp.org/index.php?topic=54879.msg592707#msg592707

Stefan

  • Bull Frog
  • Posts: 238
Re: How to grdraw / grvecs a circle?
« Reply #5 on: February 12, 2020, 09:43:22 AM »
Thanks Stefan
an interessting thing, but not what I need. But it shows the direction to use "entmake circle / delete circle" instead of grdraw.   
Please don't do that. If you can entmake/entdel then you can entmod for sure. It's just not a good idea to re-create the circle thousands times, autocad has it's limits and eventually will crash.

Peter2

  • Swamp Rat
  • Posts: 595
Re: How to grdraw / grvecs a circle?
« Reply #6 on: February 13, 2020, 02:59:32 AM »
@Augusto
thanks, I found this posting before. I suppose it is a great stuff, but to much for my simple request.

@Stefan
thanks too, but I don't need a "dynamic usage"of the circle. My program steps and zooms through the vertex of a polyline, but it stops every time. And when stopped, I use "grdraw / grvecs" to display some temporary elements
Peter

AutoCAD Map 3D 2018 German (so some technical terms will be badly retranslated to English)
BricsCAD V19

Rustabout

  • Newt
  • Posts: 51
Re: How to grdraw / grvecs a circle?
« Reply #7 on: February 13, 2020, 01:36:23 PM »
I just recently did this but with dialog box vectors. The codes methology would be applicable to grvecs (you'd need to make some sort of a list). Just a heads up: What this would do is draw a ton of lines that would "look" like a circle. An un-trained eye wouldn't know the difference. My application is a bit easier actually because I just have to repeat the "image_vector" function. I think in this case I need to build a list and plug it into grvecs.

I'll have a look at my code and see if I can make it work with grvecs. I have about half an hour (and not a great programmer). I can post the code as-is if you're curious. But I'm sure someone will come up with a real solution.

Rustabout

  • Newt
  • Posts: 51
Re: How to grdraw / grvecs a circle?
« Reply #8 on: February 13, 2020, 01:59:11 PM »
I've gotten it to work with GRDRAW. Not with GRVECS. I'm out of time (for now).

(defun C:GRDRAWTEST (/)

(defun real2int ( value / ) (atoi (rtos value 2 0)))


(setq pt1 (getpoint "Select Circle's Center: "))

(setq rad1 (getdist pt1 "Specify Circle's Radius: "))

  (setq cReps 50)  ;****************THIS LINE CONTROLS THE NUMBER OF REPETITIONS.
                   ;****************SOME NUMBERS WILL PRODUCE ERRATIC RESULTS... I THINK I NEED TO USE FACTORS OF 25



;________________ CREATE X LIST BELOW ___________________________________________________________________________________

(defun makeX_List ()

  (setq angle1 0.0)
  (setq xList (list "placeholder"))
  (setq xCounter 0)
   
  (repeat cReps
    (setq xList (append xList (list (+ (* rad1 (cos angle1)) (car pt1)))))
    (if (= (nth 0 xList) "placeholder") (setq xList (cdr xList)));skip after first pass
    (setq angle1 (+ angle1 (/ pi (/ (- cReps 1) 2)))) (setq xCounter (1+ xCounter))
    (if (>= xCounter 1)
      (progn (if (< (abs (nth (- xCounter 1) xList)) 0.001) (setq xList (subst 0 (nth (- xCounter 1) xList) xList)))))   
   );end repeat

   (setq xList (mapcar 'real2int xList))

  );end defun makeX_List

  (makeX_List)


;________________ CREATE X LIST BELOW ___________________________________________________________________________________
 
(defun makeY_List ()
 
  (setq angle1 0.0)
  (setq yList (list "placeholder"))
  (setq yCounter 0)
   
  (repeat cReps
    (setq yList (append yList (list (+ (* rad1 (sin angle1)) (car (cdr pt1))))))
    (if (= (nth 0 yList) "placeholder") (setq yList (cdr yList)));skip after first pass
    (setq angle1 (+ angle1 (/ pi (/ (- cReps 1) 2)))) (setq yCounter (1+ yCounter))
    (if (>= yCounter 1)
      (progn (if (< (abs (nth (- yCounter 1) yList)) 0.001) (setq yList (subst 0 (nth (- yCounter 1) yList) yList)))))   
   );end repeat

   (setq yList (mapcar 'real2int yList))

   );end defun makeY_List

  (makeY_List)


  ;____________________________________________________________________________

     (setq vectorCircleCounter 0)

     (repeat (- (length xList) 1)

       (grdraw (list (nth vectorCircleCounter xList) (nth vectorCircleCounter yList)) (list (nth (1+ vectorCircleCounter) xList) (nth (1+ vectorCircleCounter) yList)) 2 )

       (setq vectorCircleCounter (1+ vectorCircleCounter))

      ); end repeat

  ); END DEFUN GRDRAWTEST

AMC

  • Mosquito
  • Posts: 1
Re: How to grdraw / grvecs a circle?
« Reply #9 on: June 02, 2020, 08:51:09 AM »
not realy a circle but it got my job done :)
Code - Auto/Visual Lisp: [Select]
  1. ;imput = point lenght colorindex
  2. ;ex:    (FN_TEMPGR_CIRCLE '(1 1) 20 82)
  3. (defun FN_TEMPGR_CIRCLE ( pt LL colori / center radius arc_i arc_i_factor rtn gr_list)
  4.  
  5.         (setq rtn nil)
  6.         (setq grlist nil)
  7.         (setq center pt)
  8.         (setq radius LL)
  9.  
  10.         ;set increment factor
  11.         (setq arc_i_factor (/ (* pi 2) (* radius 12)) )
  12.         ;first point
  13.         (setq rtn (cons (polar center 0 radius) rtn))
  14.         (setq arc_i (+ 0 arc_i_factor))
  15.         ;circle points
  16.         (while (< arc_i (* pi 2))
  17.                 (setq rtn (cons (polar center arc_i radius) rtn))
  18.                 (setq arc_i (+ arc_i arc_i_factor))
  19.         )
  20.         ;last point
  21.         (setq rtn (cons (polar center 0 radius) rtn))
  22.         ;construct gr_list
  23.         (foreach elem rtn
  24.                 (setq gr_list (cons elem gr_list))
  25.                 (setq gr_list (cons colori gr_list))
  26.                 (setq gr_list (cons elem gr_list))
  27.         )
  28.         (setq gr_list (cdr (reverse (cdr (cdr gr_list)))))
  29.         ;(grvecs (reverse gr_list))
  30.         (grvecs gr_list)
  31. );end defun

dgpuertas

  • Newt
  • Posts: 52
Re: How to grdraw / grvecs a circle?
« Reply #10 on: June 03, 2020, 04:36:33 AM »

More compact:



Code: [Select]
;(while (setq pt (getpoint)) (grvecsCircle pt 3.4 4))
;(grvecsCircle (list 34 4) 43 3)

(defun grvecsCircle (pt rad col / np lst)

  (setq np 24 ;npoints
lst (mapcar (function (lambda (a) (polar pt a rad))) (rseq 0.0 (* 2. pi) np))
)
   (grvecs (apply (function append) (mapcar (function (lambda (p1 p2)
       (list col p1 p2)))
   lst (cdr lst))))
  )







(defun rseq (start endp n / lst d)
  (cond
    ((= n 1) (list start))
    ((< n 1) nil)
    ((< endp start) (reverse (rseq endp start n)))
    (T
     (setq d (/ (float (- endp start)) (1- n)))
     (repeat n
       (setq lst (cons (+ start (* (setq n (1- n)) d)) lst))))))

Lee Mac

  • Seagull
  • Posts: 12392
  • London, England
Re: How to grdraw / grvecs a circle?
« Reply #11 on: June 03, 2020, 08:18:55 AM »
More compact:
Code - Auto/Visual Lisp: [Select]
  1. (defun grvecscircle ( cen rad col / ang inc )
  2.     (setq inc (/ (+ pi pi) 24.0) ang 0.0)
  3.     (repeat 24 (grdraw (polar cen ang rad) (polar cen (setq ang (+ ang inc)) rad) col))
  4. )