Sweety Posted June 12, 2012 Posted June 12, 2012 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 Quote
Lee Mac Posted June 12, 2012 Posted June 12, 2012 (edited) 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 October 24, 2020 by Lee Mac 1 Quote
Sweety Posted June 12, 2012 Author Posted June 12, 2012 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 Quote
Lee Mac Posted June 12, 2012 Posted June 12, 2012 Two points cannot define an arc, only a line; an arc needs a minimum of three points to be defined. Quote
Sweety Posted June 12, 2012 Author Posted June 12, 2012 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 Quote
Lee Mac Posted June 12, 2012 Posted June 12, 2012 (edited) Here is an example: (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 October 24, 2020 by Lee Mac Quote
Sweety Posted June 18, 2012 Author Posted June 18, 2012 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 Quote
ketxu Posted June 18, 2012 Posted June 18, 2012 Just divide your arc curve to many line and make grdraw (grvecs), combine with grread is more fun Quote
dexus Posted January 28, 2021 Posted January 28, 2021 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.dwg Quote
dexus Posted January 29, 2021 Posted January 29, 2021 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.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) ) Quote
Recommended Posts
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.