Author Topic: Challenge ( Kind of ) Arc Entmake Data  (Read 9018 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: 12913
  • 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: 12913
  • 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: 12913
  • 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))

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #15 on: April 10, 2010, 02:15:27 PM »
Its much more easy with .NET

Code: [Select]
private void MakeArc(Point3d p1, Point3d p2, Point3d p3)
{
    Database db = HostApplicationServices.WorkingDatabase;
    using (Transaction tr = db.TransactionManager.StartTransaction())
    {
        CircularArc3d arc = new CircularArc3d(p1, p2, p3);
        BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
        Arc a = new Arc(arc.Center, arc.Radius, arc.StartAngle, arc.EndAngle);
        btr.AppendEntity(a);
        tr.AddNewlyCreatedDBObject(a, true);
        tr.Commit();
    }
}
Speaking English as a French Frog

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #16 on: April 10, 2010, 02:17:23 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))

Haha, very funny  :-D

LE3

  • Guest
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #17 on: April 10, 2010, 02:25:46 PM »
forgot to use quote instead of code to show it right :)

I made in the way past 18 new method to draw arcs, if I get a permit will try to post them, but you guys are way to smart - that do not need anything  :wink:

Quote
Haha, very funny  :-D
« Last Edit: April 10, 2010, 02:29:28 PM by LE3 »

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #18 on: April 10, 2010, 02:35:49 PM »
but you guys are way to smart - that do not need anything  :wink:

Thanks Luis, but honestly - Gile is leaps and bounds ahead of me, I always learn a great deal from him.

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #19 on: April 10, 2010, 03:01:51 PM »
Okay,  that makes sense now.  Thanks!  -David
R12 Dos - A2K

hermanm

  • Guest
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #20 on: April 10, 2010, 03:35:49 PM »

 if I get a permit will try to post them


What's this about a "permit," Luis?

Did I miss something?    :?

LE3

  • Guest
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #21 on: April 10, 2010, 04:11:58 PM »
did those for someone else... was a paid stuff. :)


 if I get a permit will try to post them


What's this about a "permit," Luis?

Did I miss something?    :?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #22 on: April 10, 2010, 04:22:52 PM »
Another version using code from Evgeniy & Gile
Code: [Select]
;;  Points Start, along,& end of the arc
(defun Arc3pt (ps pm pe / r cen tmp)
  (defun clockwise-p (p1 p2 p3) ; gile
    (< (sin (- (angle p1 p3) (angle p1 p2))) -1e-14)
  )
  (if (clockwise-p ps pm pe)
    (setq tmp ps ps pe pe tmp)
  )
  (setq cen (polar pe  ; Evgeniy
              (+ (angle pe pm)
(setq r (- (angle ps pe) (angle ps pm)))
(* pi -0.5)
      )
              (setq r (/(distance pm pe) (sin r) 2.))
       ))
  (setq r  (abs 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)
  )
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.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #23 on: April 10, 2010, 04:35:46 PM »
There's a tool I don't know the English name wich use this property to draw radius and/or find the center of round pieces of wood or iron.
Here's how it looks and how it works:
Speaking English as a French Frog

LE3

  • Guest
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #24 on: April 10, 2010, 04:40:21 PM »
There's a tool I don't know the English name
what's the name in French?

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #25 on: April 10, 2010, 04:48:25 PM »
the french name is: équerre à centrer it's mostly used by turners.
« Last Edit: April 10, 2010, 04:51:27 PM by gile »
Speaking English as a French Frog

LE3

  • Guest
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #26 on: April 10, 2010, 04:52:45 PM »
the french name is: équerre à centrer it's mostly used by turners.

maybe something like:
supported to the center... bracket to center

:)

 :-o
hmmm.... I see that it is an instrument
the square = équerre
« Last Edit: April 10, 2010, 04:57:56 PM by LE3 »

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #27 on: April 10, 2010, 05:02:17 PM »
'bracket to center' is what google translator gives.

IMO litteral translation should rather be 'set-square to center'
Speaking English as a French Frog

LE3

  • Guest
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #28 on: April 10, 2010, 05:06:19 PM »
'bracket to center' is what google translator gives.

IMO litteral translation should rather be 'set-square to center'
Yes, it makes sense.

That can be a good candidate for a custom object, btw. or maybe with these new parametric features or as a dynamic block.... don't know.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #29 on: April 10, 2010, 05:08:29 PM »
Some other designs:


Speaking English as a French Frog

xyp1964

  • Guest
Re: Challenge ( Kind of ) Arc Entmake Data
« Reply #30 on: April 13, 2010, 08:43:04 AM »
Quote
;; ArcWith3pt (ArcWith3pt p1 p2 p3)
(defun ArcWith3pt (P1 P2 P3)
  (defun 3d2d (point)
    (if   (= (length point) 3)
      (list (car point) (cadr point))
      point
    )
  )
  (command "ucs" "n" "3" "non" p1 "non" p2 "non" p3)
  (command "arc"
      "non"
      (3d2d (trans P1 0 1))
      "non"
      (3d2d (trans P2 0 1))
      "non"
      (3d2d (trans P3 0 1))
  )
  (command "ucs" "p")
  (entlast)
)