Author Topic: Challenge ( Kind of ) Arc Entmake Data  (Read 9031 times)

0 Members and 1 Guest are viewing this topic.

David Bethel

  • Swamp Rat
  • Posts: 656
Challenge ( Kind of ) Arc Entmake Data
« on: April 10, 2010, 09:36:33 AM »
Greetings,

I've had this one on the back burner for a while, and now it's came to a must do.

In vanilla autolisp ( no vl vla vlax ), I need to find the entmake data ( groups 10 40 50 51 ) for an arc with the known values of start_point second_point and end_point only.
( the default arc input values )

What's forcing this is the body on serving carts is set in 1.5" on the curved sides versus 0.5 on the ends. And I need make stainless corner caps on each corner.

Any ideas are appreciated.  -David
R12 Dos - A2K

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #2 on: April 10, 2010, 10:38:22 AM »
Not sure David but are you wanting to do an ssget for the Start, End, and Mid point of an arc?
If so you know that you will have to process each arc to ascertain that data.

More formulas
Code: [Select]
  (setq en (ssname ss 0)
        ed (entget en)
        et (cdr (assoc 0 ed)) ;entity type
        ha (cdr (assoc 5 ed)) ;handle
        lt (cdr (assoc 6 ed)) ;linetype
        la (cdr (assoc 8 ed)) ;layer
        tk (cdr (assoc 39 ed)) ;thickness
        ls (cdr (assoc 48 ed)) ;lt scale
        ac (cdr (assoc 62 ed)) ;color
        uc (cdr (assoc 210 ed)) ;ucs
        ce (cdr (assoc 10 ed)) ;center
        ra (cdr (assoc 40 ed)) ;radius
        sa (cdr (assoc 50 ed)) ;start angle
        ea (cdr (assoc 51 ed)) ;end angle
        p1 (polar ce sa ra) ;start point
        p2 (polar ce ea ra) ;end point
        cd (distance p1 p2) ;chord distance
        ca (angle p1 p2) ;chord angle
        mc (mapcar '(lambda (a b) (* (+ a b) 0.5)) p1 p2) ;mid point of chord
        ch (- ra (distance ce mc)) ;chord height
        ia (if (> ea sa)
             (- ea sa)
             (+ ea (- (* pi 2) sa))
           ) ;included angle
        mp (polar ce (+ sa (* 0.5 ia)) ra) ;arc mid point
        al (* pi (* ra 2) (/ ia (* pi 2))) ;arc length
        wa (* pi (* ra ra) (/ ia (* pi 2))) ;wedge area
        aa (- wa (area-triangle ce p1 p2))
  )
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #3 on: April 10, 2010, 10:51:36 AM »
Thanks Evgeniy, very useful information. :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #4 on: April 10, 2010, 11:09:03 AM »
Cab,

I have the 3 point info.  I need to entmake the ARC based on those values only.

So far:

The chord from start to end, therfore the mid point of the chord.

In this case the second point is the mid point of the arc, but thats not always the case

So I guess I could form a a right triangle from an end_point, mid_chord_pt, and mid_arc_pt

I think there is a formula to determine the center based on chord length and chord height ( Somewhere floating around me feeble mind)   -David
R12 Dos - A2K

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #5 on: April 10, 2010, 11:40:27 AM »
Found part of it.

From Jim Fisher
Code: [Select]
; r is the arc's rdius
 ; c is half the distance from pt1 to pt2 and
 ; h is the "rise of the arc" between pt1 and pt2
 ;

 ;
 ;         (c * c) + (h * h)
 ;    r = -------------------
 ;               2 * h
 ;

(setq r (/ (+ (* c c) (* h h)) (* 2 h)))



Now to implement it.....  -David
R12 Dos - A2K

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #6 on: April 10, 2010, 12:55:22 PM »
Hi,

The arc center is the intersection of 2 chord mediators (perpendicular at the middle of the segment). Using polar and inters function it's quite easy to determine the arc center and then its radius, start and end angles.

Arc datas (StartAngle and EndAngle) are always counterclockwise, so it's needed to permute the first and third point if the points aren't clockwise.

Code: [Select]
(defun ArcBy3Pts (p1 p2 p3 / m1 m2)
  (if (clockwise-p p1 p2 p3)
    (permute 'p1 'p3)
  )
  (and
    (setq m1 (midPt p1 p2))
    (setq m2 (midPt p2 p3))
    (setq pi/2 (/ pi 2))
    (setq c (inters m1
    (polar m1 (+ (angle p1 p2) pi/2) 1.)
    m2
    (polar m2 (+ (angle p2 p3) pi/2) 1.)
    nil
    )
    )
    (setq a1 (angle c p1))
    (setq a2 (angle c p3))
    (entmake
      (list
'(0 . "ARC")
(cons 10 c)
(cons 40 (distance c p1))
(cons 50 a1)
(cons 51 a2)
      )
    )
  )
)

;; Clockwise-p
;; Evaluates if p1 p2 p3 are clockwise
(defun clockwise-p (p1 p2 p3)
  (< (sin (- (angle p1 p3) (angle p1 p2))) -1e-14)
)

;; MidPt
;; Returns the middle of p1 p2
(defun midpt (p1 p2)
  (mapcar '(lambda (x1 x2) (/ (+ x1 x2) 2.)) p1 p2)
)

;; Permute
;; Permutes the datas bounded to a and b
(defun permute (a b / c)
  (setq c (eval a))
  (set a (eval b))
  (set b c)
)
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #7 on: April 10, 2010, 01:05:33 PM »
Haha I was just about to post this Gile... looks like you beat me to it  :-P

Code: [Select]
(defun 3PointArc (p1 p2 p3 / mid clockwise-p ANG1 ANG2 CEN EANG MID1 MID2 RAD SANG)

  (defun mid (p1 p2)
    (mapcar (function /)
            (mapcar (function +) p1 p2) '(2. 2.)))

  (defun clockwise-p (p1 p2 p3) ; Gile
    (< (sin (- (angle p1 p3) (angle p1 p2))) -1e-14))
 
  (setq ang1 (angle p1 p2) ang2 (angle p2 p3)
        mid1 (mid p1 p2)   mid2 (mid p2 p3)
 
        cen  (inters mid1 (polar mid1 (+ ang1 (/ pi 2.)) 1.)
                     mid2 (polar mid2 (+ ang2 (/ pi 2.)) 1.) nil)
       
        rad  (distance cen p1))

  (if (clockwise-p p1 p2 p3)
    (setq sAng (angle cen p3)
          eAng (angle cen p1))
    (setq sAng (angle cen p1)
          eAng (angle cen p3)))

  (entmakex (list (cons 0 "ARC")
                  (cons 10 cen)
                  (cons 40 rad)
                  (cons 50 sAng)
                  (cons 51 eAng))))

It uses one of your subs anyway...



EDIT: Alternatively, if you wish to use Bulge :



Code: [Select]
;; BulgeData  ~  Lee Mac
;; Args: p1,p2 Points, b Bulge
;; Returns:  (<centre> <inc. angle> <radius>)

(defun BulgeData (p1 p2 b / theta/2 radius centre)
  (setq theta/2 (* 2. (atan b))
        radius  (/ (distance p1 p2) (* 2. (sin theta/2)))
        centre  (polar p1 (+ (- (/ pi 2.) theta/2) (angle p1 p2)) radius))

  (list centre (* 2. theta/2) (abs radius)))
« Last Edit: April 10, 2010, 01:10:11 PM by Lee Mac »

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #8 on: April 10, 2010, 01:10:55 PM »
All of these work good if p2 ( or the second point ) is the middle of the arc segment.  What if it isn't?  ARC and CICRLE commands both take 3 random point inputs.  -David
R12 Dos - A2K

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #9 on: April 10, 2010, 01:15:47 PM »
All of these work good if p2 ( or the second point ) is the middle of the arc segment.  What if it isn't?  ARC and CICRLE commands both take 3 random point inputs.  -David

P2 does not have to be in the center of the Arc - it will work wherever p1, p2, p3 are relative to each other.

Example:

« Last Edit: April 10, 2010, 01:18:57 PM by Lee Mac »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #10 on: April 10, 2010, 01:50:22 PM »
Boy, you guys a way ahead of me.  :?
Code: [Select]
(defun Arc3pt(ps pm pe / ps pe pm tmp cl cmpt ch r cen)

  ;; Evaluates if p1 p2 p3 are clockwise - gile
(defun clockwise-p (p1 p2 p3)
  (< (sin (- (angle p1 p3) (angle p1 p2))) -1e-14)
)

  (if (clockwise-p ps pm pe)
    (setq tmp ps ps pe pe tmp)
  )
  (setq cl (distance ps pe))
  (setq cmpt  (polar ps (angle ps pe) (/ (distance ps pe) 2.)))
  (setq ch  (distance cmpt pm))
  (setq r  (/ (+ (* cl cl) (* (* ch ch)4)) (* 8 ch)))
  (setq cen (polar pm (angle pm cmpt) r))

  (entmakex
    (list (cons 0 "ARC")
               (cons 6 "BYLAYER")
               ;(cons 8 "0")
               (cons 10 cen) ;*** Center point (in OCS)
               (cons 40 r) ;*** Radius
               (cons 50 (angle cen ps)) ;*** Start angle
               (cons 51 (angle cen pe)) ;*** End angle
               ))
  (princ)
  )
« Last Edit: April 10, 2010, 04:13:04 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

LE3

  • Guest
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #11 on: April 10, 2010, 01:53:56 PM »
and if you use the command or vl-cmdf and just pass the first - mid - end points to the _.arc command ? (mid can be any where)

I have the 3 point info.  I need to entmake the ARC based on those values only.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #12 on: April 10, 2010, 01:54:41 PM »
and if you use the command or vl-cmdf and just pass the first - mid - end points to the _.arc command ? (mid can be any where)

I have the 3 point info.  I need to entmake the ARC based on those values only.

Where's the fun in that...  :evil:

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #13 on: April 10, 2010, 01:55:48 PM »
All of these work good if p2 ( or the second point ) is the middle of the arc segment.  What if it isn't?  ARC and CICRLE commands both take 3 random point inputs.  -David

It even works using p1 p2 and p1 p3
« Last Edit: April 10, 2010, 01:59:27 PM by gile »
Speaking English as a French Frog

LE3

  • Guest
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #14 on: April 10, 2010, 01:59:41 PM »
Where's the fun in that...  :evil:

See below on the bold letters, is there    :evil:
Code: [Select]
(de[b]fun[/b] c:arc3pts (/ p1 p2 p3)
(setq p1 (getpoint "\nStart point: ")
      p3 (getpoint "\nMid point: ")
      p2 (getpoint "\nEnd point: "))
(vl-cmdf "_.ARC" p1 p3 p2) (princ))