Jump to content

Draw arc with grdraw or grvecs or any other graphics ways


Sweety

Recommended Posts

hello guys .

 

I know with grdraw and grvecs and maybe lots of other ways can draw continuous lines , but I need to draw graphic arc to allow me to improve the shape before drawing it with entmake or command .

 

can anyone help me please .

 

Thanxxxx :)

Link to comment
Share on other sites

An example,

;; 3-Point grvecs Arc  -  Lee Mac
;; Example to display a 3-Point Arc using grvecs

(defun c:grarc ( / _grarc p1 p2 p3 lst )

   (defun _grarc ( sa ea / in pl )
       (setq in (/ (rem (+ pi pi (- ea sa)) (+ pi pi)) 25.0))
       (repeat 26
           (setq pl (cons (polar '(0.0 0.0) sa 1.0) pl)
                 sa (+ sa in)
           )
       )
       (apply 'append (mapcar 'list pl (cdr pl)))
   )
   
   (if
       (and
           (setq p1 (getpoint "\nPick 1st Point: "))
           (setq p2 (getpoint "\nPick 2nd Point: "))
           (setq p1 (trans p1 1 0)
                 p2 (trans p2 1 0)
           )
       )
       (while (= 5 (car (setq p3 (grread nil 13 0))))
           (redraw)
           (if (setq lst (LM:3PArc p1 p2 (trans (cadr p3) 1 0)))
               (grvecs (cons -3 (_grarc (cadr lst) (caddr lst)))
                   (list
                       (list (cadddr lst) 0.0 0.0 (caar  lst))
                       (list 0.0 (cadddr lst) 0.0 (cadar lst))
                       (list 0.0 0.0 (cadddr lst) 0.0)
                       (list 0.0 0.0 0.0 1.0)
                   )
               )
           )
       )
   )
   (redraw) (princ)
)

;; 3-Point Arc  -  Lee Mac
;; Returns the Center, Start/End Angle and Radius of the
;; Arc defined by three supplied points.

(defun LM:3PArc ( p1 p2 p3 / cn m1 m2 )
   (setq m1 (mid p1 p2)
         m2 (mid p2 p3)
   )
   (if
       (setq cn
           (inters
               m1 (polar m1 (+ (angle p1 p2) (/ pi 2.)) 1.0)
               m2 (polar m2 (+ (angle p2 p3) (/ pi 2.)) 1.0)
               nil
           )
       )
       (append (list cn)
           (if (LM:Clockwise-p p1 p2 p3)
               (list (angle cn p3) (angle cn p1))
               (list (angle cn p1) (angle cn p3))
           )
           (list (distance cn p1))
       )
   )
)

;; Midpoint  -  Lee Mac
;; Returns the midpoint of two points

(defun mid ( a b )
   (mapcar (function (lambda ( a b ) (/ (+ a b) 2.0))) a b)
)

;; Clockwise-p  -  Lee Mac
;; Returns T if p1,p2,p3 are clockwise oriented

(defun LM:Clockwise-p ( p1 p2 p3 )
   (< (* (- (car  p2) (car  p1)) (- (cadr p3) (cadr p1)))
      (* (- (cadr p2) (cadr p1)) (- (car  p3) (car  p1)))
   )
)

Some more examples:

http://lee-mac.com/3pointarccircle.html

Edited by Lee Mac
  • Thanks 1
Link to comment
Share on other sites

Thanks lee , that is not what I need . :(

 

I need to specify two points and at the end of the second point I need to draw arc with grdraw or grvecs or any other way .

 

example .

 

(grdraw p1 p2 1 1) but how to make it for arc ?

 

Thankxxxxxx

Link to comment
Share on other sites

yes that is right .

 

(setq p1 (getpoint "\n 1st point :"))

(setq p2 (getpoint "\n 2nd point :" p1))

(setq p3 (polar p2 (+ (angle p1 p2) 1.5708 ) 2.0))

(setq p4 (polar p3 (angle p1 p2) 2.0))

(grdraw p1 p2 1 1)

 

 

points (p2 p3 p4) are for example start , center and end .

 

how can i use grdraw or any other functions to draw the arc like the way for line ( graphically ) ?

 

Thanks

Link to comment
Share on other sites

Here is an example:

 

GrArcExample.gif

(defun c:test ( / a1 a2 p1 p2 pl )
   (if (setq p1 (getpoint "\nPick 1st Point: "))
       (progn
           (setq a1 (* pi 0.05)
                 a2 (* pi  1.5)    
           )
           (repeat 11
               (setq pl (cons (polar '(0.0 2.0 0.0) a2 2.0) pl)
                     a2 (+ a2 a1)
               )
           )
           (setq pl (apply 'append (mapcar 'list pl (cdr pl))))
           (princ "\nPick 2nd Point: ")
           (while (= 5 (car (setq p2 (grread nil 13 0))))
               (setq p2 (cadr p2)
                     a1 (angle p1 p2)
               )
               (redraw)
               (grvecs (list 3 p1 p2))
               (grvecs (cons 3 pl)
                   (list
                       (list (cos a1) (- (sin a1)) 0.0 (car  p2))
                       (list (sin a1)    (cos a1)  0.0 (cadr p2))
                      '(0.0 0.0 1.0 0.0)
                      '(0.0 0.0 0.0 1.0)
                   )
               )
           )
       )
   )
   (redraw) (princ)
)
 
Edited by Lee Mac
Link to comment
Share on other sites

:(

 

Still not what I want , the function grdraw would draw from point to point as a line only , and i want function with three points to draw arc with the same graphic of function grdraw .

 

Thank you

Link to comment
Share on other sites

  • 8 years later...
On 6/12/2012 at 2:36 PM, Lee Mac said:

An example,


;; 3-Point grvecs Arc  -  Lee Mac
;; Example to display a 3-Point Arc using grvecs

(defun c:grarc ( / _grarc p1 p2 p3 lst )

   (defun _grarc ( sa ea / in pl )
       (setq in (/ (rem (+ pi pi (- ea sa)) (+ pi pi)) 25.0))
       (repeat 26
           (setq pl (cons (polar '(0.0 0.0) sa 1.0) pl)
                 sa (+ sa in)
           )
       )
       (apply 'append (mapcar 'list pl (cdr pl)))
   )
   
   (if
       (and
           (setq p1 (getpoint "\nPick 1st Point: "))
           (setq p2 (getpoint "\nPick 2nd Point: "))
           (setq p1 (trans p1 1 0)
                 p2 (trans p2 1 0)
           )
       )
       (while (= 5 (car (setq p3 (grread nil 13 0))))
           (redraw)
           (if (setq lst (LM:3PArc p1 p2 (trans (cadr p3) 1 0)))
               (grvecs (cons -3 (_grarc (cadr lst) (caddr lst)))
                   (list
                       (list (cadddr lst) 0.0 0.0 (caar  lst))
                       (list 0.0 (cadddr lst) 0.0 (cadar lst))
                       (list 0.0 0.0 (cadddr lst) 0.0)
                       (list 0.0 0.0 0.0 1.0)
                   )
               )
           )
       )
   )
   (redraw) (princ)
)

;; 3-Point Arc  -  Lee Mac
;; Returns the Center, Start/End Angle and Radius of the
;; Arc defined by three supplied points.

(defun LM:3PArc ( p1 p2 p3 / cn m1 m2 )
   (setq m1 (mid p1 p2)
         m2 (mid p2 p3)
   )
   (if
       (setq cn
           (inters
               m1 (polar m1 (+ (angle p1 p2) (/ pi 2.)) 1.0)
               m2 (polar m2 (+ (angle p2 p3) (/ pi 2.)) 1.0)
               nil
           )
       )
       (append (list cn)
           (if (LM:Clockwise-p p1 p2 p3)
               (list (angle cn p3) (angle cn p1))
               (list (angle cn p1) (angle cn p3))
           )
           (list (distance cn p1))
       )
   )
)

;; Midpoint  -  Lee Mac
;; Returns the midpoint of two points

(defun mid ( a b )
   (mapcar (function (lambda ( a b ) (/ (+ a b) 2.0))) a b)
)

;; Clockwise-p  -  Lee Mac
;; Returns T if p1,p2,p3 are clockwise oriented

(defun LM:Clockwise-p ( p1 p2 p3 )
   (< (* (- (car  p2) (car  p1)) (- (cadr p3) (cadr p1)))
      (* (- (cadr p2) (cadr p1)) (- (car  p3) (car  p1)))
   )
)

Some more examples:

http://lee-mac.com/3pointarccircle.html

 

I know this is an old thread, but I used the code above for a project of mine and have encountered a problem with it.

In one of my drawings the line is rendered in a different place from the cursor. Not sure why this is happening, maybe something to do with the ucs?

 

Here is an example, and below is the drawing in which this happens. Anyone know what is wrong?

 

tan.thumb.gif.d8592b0a8267865c18984dbef4a233a6.gif

tan.dwg

Link to comment
Share on other sites

21 hours ago, dexus said:

 

I know this is an old thread, but I used the code above for a project of mine and have encountered a problem with it.

In one of my drawings the line is rendered in a different place from the cursor. Not sure why this is happening, maybe something to do with the ucs?

 

Here is an example, and below is the drawing in which this happens. Anyone know what is wrong?

 

tan.thumb.gif.d8592b0a8267865c18984dbef4a233a6.gif

tan.dwg 103.65 kB · 1 download

 

I managed to make it work by getting rid of the matrix conversion.

Not sure how to do it with the matrix, but this works for now.

;; 3-Point grvecs Arc  -  Lee Mac
;; Example to display a 3-Point Arc using grvecs

(defun c:grarc ( / _grarc p1 p2 p3 lst )

   (defun _grarc ( sa ea pt radius / in pl )
       (setq in (/ (rem (+ pi pi (- ea sa)) (+ pi pi)) 25.0))
       (repeat 26
           (setq pl (cons (polar pt sa radius) pl)
                 sa (+ sa in)
           )
       )
       (apply 'append (mapcar 'list pl (cdr pl)))
   )
   
   (if
       (and
           (setq p1 (getpoint "\nPick 1st Point: "))
           (setq p2 (getpoint "\nPick 2nd Point: "))
           (setq p1 (trans p1 1 0)
                 p2 (trans p2 1 0)
           )
       )
       (while (= 5 (car (setq p3 (grread nil 13 0))))
           (redraw)
           (if (setq lst (LM:3PArc p1 p2 (trans (cadr p3) 1 0)))
               (grvecs (cons -3 (_grarc (cadr lst) (caddr lst) (car lst) (cadddr lst))))
           )
       )
   )
   (redraw) (princ)
)

 

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