Arcs in wrong direction

Arcs in wrong direction

etilley327KA
Advocate Advocate
923 Views
9 Replies
Message 1 of 10

Arcs in wrong direction

etilley327KA
Advocate
Advocate

Can someone show me how to make that arcangle go in the right direction to produce the desired arclength. Also, when using the Left direction it faces to the wrong side.

 

etilley327KA_0-1684516615000.png

(defun c:test (/ *error* pnt backsight turn rad)
(defun *error* ( msg )
        (if savOSnap (setvar 'savOSnap))
        (if (not (member msg '("Function cancelled" "quit / exit abort")))
            (princ (strcat "\nError: " msg))
        )
        (princ)
)
(setq savOSnap  (getvar "osmode"))
(setvar "osmode" 1)
(setq pnt (getpoint "\nSelect Point: "))
(setq rad (getreal "\nEnter Radius: "))
(setq arclen (getreal "\Enter Arc Length: "))
(princ (strcat "arclen- " (rtos arclen)))
(princ "\n ")
(initget "Right Left")
(if (/= "Left" (getkword "\nRight or Left? [Right/Left] <R>: "))
  (setq turn (/ pi 2.0))
  (setq turn (- (/ pi 2.0)))
)
;(princ turn)
(setvar "osmode" 512)
(setq backsight (getpoint "\nSelect backsight: "))
(setq backangle (angle pnt backsight))
(princ (strcat "backangle- " (rtos backangle)))
(princ "\n ")
(setq centangle (+ backangle turn))
(princ (strcat "centangle- " (rtos centangle)))
(princ "\n ")
(setq centerPoint (polar pnt centangle rad))
(setq arc (/ arclen rad))
(princ (strcat "arc- " (rtos arc)))
(princ "\n ")
(setq arcangle (+ centangle arc))
(princ (strcat "arcangle- " (rtos arcangle)))
(princ "\n ")
(setq arcpnt (polar centerPoint arcangle rad))
(command "line" pnt centerPoint "")
(command "line" centerPoint arcpnt "")
;(princ centerPoint)
;(princ pnt)
(princ (strcat "rad- " (rtos rad)))
;(princ backsight)
(setvar "osmode" savOSnap)
)
0 Likes
Accepted solutions (1)
924 Views
9 Replies
Replies (9)
Message 2 of 10

Kent1Cooper
Consultant
Consultant

Where in the diagram is 'pt'?

 

I see nothing in the code that draws an Arc, which makes it hard to imagine how it could be drawing it in the wrong direction.  Is something missing?  Am I misunderstanding what you're trying to do?

Kent Cooper, AIA
0 Likes
Message 3 of 10

etilley327KA
Advocate
Advocate

Haha! Sorry, I haven't got that far yet. I just have the points and the temp lines for now. The second line is what im referring to, which is coming in at the wrong angle. Which would subsequently give me an arc in the wrong direction.

0 Likes
Message 4 of 10

Moshe-A
Mentor
Mentor

@etilley327KA ,

 

i ran TEST command and got 2 unclear lines?!

 

you should be aware to this - AutoCAD rule for arcs:

a positive angle (bulge) draw the arc CCW (CounterClockWise)

a negative angle draw the arc CW (ClockWise)

 

Moshe

 

0 Likes
Message 5 of 10

Kent1Cooper
Consultant
Consultant

I'm still not sure exactly what you're trying to do.  Can you just draw the upper part and MIRROR it for the lower part?

Kent Cooper, AIA
0 Likes
Message 6 of 10

etilley327KA
Advocate
Advocate

Sorry, im trying to learn how to draw an arc with angles. I thought i needed a starting point a center point and the end. Im having trouble getting the polar point for the end at the right spot according to the requested length of the arc. Im tring to get this correct before i move on to makeing the arc go in the correc (clockwise/ counterclockwise) direction. 

etilley327KA_0-1684524016288.png

 

0 Likes
Message 7 of 10

Kent1Cooper
Consultant
Consultant

@etilley327KA wrote:

.... I thought i needed a starting point a center point and the end. I.... 


There are 8 ways to draw an Arc.  Maybe some other combination of known elements will serve you better.  Experiment with the ARC command manually and try all the options offered to see the various ways it can be done.

 

[By the way, it looks like you are using the "Reply to topic" slot at the bottom.  Things entered there always show as being in Reply to Message 1, and therefore to (in this case) yourself.  Use the Reply button at lower right in the Message you're Replying to, and it will show as being in Reply to the author of that, not to yourself.]

Kent Cooper, AIA
Message 8 of 10

etilley327KA
Advocate
Advocate
Accepted solution
I needed to add it to PI. (setq arc (+ PI (/ arclen rad)))
0 Likes
Message 9 of 10

Moshe-A
Mentor
Mentor

@etilley327KA ,

 

Already close it? Care to check my version? 😀

this one (i hope) works in any direction but start the opposite way from your.

you pick the backsite far point, than the other point which become the arc start point

the backsite line is done here with (grdraw) and is clear at exist but in case of error a redraw will clear it.

 

About the Right/Left turn? i used (getdist) to show the direction of arc,  it's more intuitive - agree?!

 

a good programming structure first ask for user all input data (of course if it's possible) than goes to process.

another thing to be aware is data input check. at any stage user may exist the program without any error return.

and you were correct, this is very tricky no picnic in park 🤣

 

enjoy

Moshe

 

(defun c:ArcLength (/ qang whichAngle)
                      savOrthoMode p0 p2 p2 p5 c0 r0 alen ang0 ang1 ang2 ang3 ang4 ang5)

 (defun qang (a0 a1 / a2)
  (if (> a0 a1)
   (setq a2 (- a0 a1))
   (setq a2 (- a1 a0))
  )

  (if (> a2 pi)
   (- (* pi 2) a2)
   a2)
 ); qang

 (defun whichAngle (t0 t1 t2 / a0 a1 a2 bx t3)
  (setq a0 (angle t1 t0))
  (setq a1 (angle t1 t2))

  (setq a2 (qang a0 a1))
  (setq bx (* (cos a2) (distance t1 t2))) 
  (setq t3 (polar t1 a0 bx))
    
  (angle t3 t2)	  
 ); whichAngle


 ; here start c:ArcLength
 (setvar "cmdecho" 0)
 (command "._undo" "_begin")

 (setq savOrthoMode (getvar "orthomode")) 
  
 (if (and
	(setq p0 (getpoint "\nSpecify backsite startpoint: "))
	(setq p1 (getpoint p0 "\nSpecify backsite endpoint: "))
	(not (grdraw p0 p1 7))
        (setq r0 (getdist p1 "\nArc radius: "))
	(setq alen (getdist p1 "\nArc length: "))
        (setq p2 (getpoint p1 "\nWhich side? "))
      )
  (progn
   (setvar "orthomode" 0)
   
   (setq ang0 (angle p0 p1))
   (setq ang1 (angle p1 p0))
   (setq ang2 (whichAngle p0 p1 p2)) 
   (setq c0 (polar p1 ang2 r0))   ; arc center point
   (setq ang3 (/ alen r0))        ; include angle
   (setq ang4 (angle c0 p1))
    
   (cond
    ((> ang2 ang1)
     (if (> (- ang2 ang1) pi)
      (progn	
       (setq ang5 (+ ang3 ang4))
       (setq p5 (polar c0 ang5 r0))
       (command "._arc" "_none" p1 "_C" "_none" c0 "_none" p5)
      ); progn
      (progn
       (setq ang5 (- ang4 ang3))
       (setq p5 (polar c0 ang5 r0))
       (command "._arc" "_none" p5 "_C" "_none" c0 "_none" p1)
      ); progn
     ); if
    ); case
    ((< ang2 ang1)
     (if (> (- ang1 ang2) pi)
      (progn  	
       (setq ang5 (- ang4 ang3))
       (setq p5 (polar c0 ang5 r0))
       (command "._arc" "none" p5 "_C" "none" c0 "none" p1)
      ); progn
      (progn
       (setq ang5 (+ ang3 ang4))
       (setq p5 (polar c0 ang5 r0))
       (command "._arc" "none" p1 "_C" "none" c0 "none" p5)
      ); progn
     ); if
    ); case
   ); cond

   (grdraw p0 p1 0) ; clear grdraw line
  ); progn
 ); if

 (setvar "orthomode" savOrthoMode)
  
 (command "._undo" "_end")
 (setvar "cmdecho" 0)
  
 (princ) 
); c:ArcLength

 

 

0 Likes
Message 10 of 10

komondormrex
Mentor
Mentor

hey, get it simplier)

 

(defun c:draw_arc ()
	(setq arc_start_point (trans (getpoint "\nPick arc start point: ") 1 0)
	      arc_center_point (trans (getpoint arc_start_point"\nPick center point: ") 1 0)
	      arc_length (getreal "\nEnter arc distance (positive is CCW, negative is CW): ")
	      arc_included_angle (/ arc_length (setq arc_radius (distance arc_start_point arc_center_point)))
	      arc_start_angle (angle arc_center_point arc_start_point)
	      arc_end_angle (+ arc_start_angle arc_included_angle)
	)
	(vla-addarc (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
		    (vlax-3d-point arc_center_point)
	  	    arc_radius
	  	    (if (minusp arc_included_angle) arc_end_angle arc_start_angle)
	  	    (if (minusp arc_included_angle) arc_start_angle arc_end_angle)
	)
)

 

0 Likes