Author Topic: How to get arc  (Read 2048 times)

0 Members and 1 Guest are viewing this topic.

Adesu

  • Guest
How to get arc
« on: May 06, 2007, 11:01:30 PM »
Hi Alls,
I just got in others forum, he got trouble to find an arc in polyline object, he want value of the start angle and end angle,any idea ?

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: How to get arc
« Reply #1 on: May 07, 2007, 12:00:58 AM »
No time for a full program, but here's enough to get you well on your way to a finished product.
Thanks to Jürg Menzi for the code to calc bulge data.
Code: [Select]
(setq osmode (getvar "osmode"))
(setvar "osmode" 512)
(if (and (setq pt (getpoint "\nSelect pline: "))
(setq pline (nentselp pt))
    )
  (progn
    (setq oPline (vlax-ename->vla-object (car pline)))
    (setq param (fix (vlax-curve-getparamatpoint
       oPline
       pt
     )
)
    )
    (setq bulge (vla-getbulge oPline param))
    (setq begincurve (vlax-safearray->list
       (vlax-variant-value
(vla-get-coordinate oPline param)
       )
     )
  endcurve   (vlax-safearray->list
       (vlax-variant-value
(vla-get-coordinate oPline (1+ param))
       )
     )
    )
    ;|-----------------------------------------------------------
Used by permission from Jürg Menzi
; -- Function CalcBulge
; Returns the geometric informations from a polyarc.
; Copyright:
;   2001 MENZI ENGINEERING GmbH, Switzerland
; Arguments [Typ]:
;   Vx1 = Start vertex of p'arc [LIST]
;   Vx2 = End vertex of p'arc [LIST]
;   Blg = Bulge [REAL]
; Return [Typ]:
;   > '(CenterPoint Radius IncludedAngle) [LIST]
; Notes:
;   IncludedAngle in radians
|;
    (defun CalcBulge (Vx1 Vx2 Blg / ArcRad CenDir HlfAng)
      (setq HlfAng (* 2 (atan Blg))
    CenDir ((if (< Blg 0)
      -
      +
    )
     (- (angle Vx1 Vx2) HlfAng)
     (/ pi 2)
   )
    ArcRad (abs (/ (/ (distance Vx1 Vx2) 2.0) (sin HlfAng)))
      )
      (list
(polar Vx1 CenDir ArcRad)
ArcRad
(* (abs HlfAng) 2.0)
      )
    )
    (setq bulgedata (calcbulge begincurve endcurve bulge))
    ;;the bulgdata will hold the RadiusPt coordinates, the radius and the Internal angle in Radians
;;;;
    ;;and now that you have the start, end & radius pts the begin & end angles are easily calc'ed
  )
)

Adesu

  • Guest
Re: How to get arc
« Reply #2 on: May 07, 2007, 01:18:50 AM »
Hi Jeff_M,
it's great,thanks you very much.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: How to get arc
« Reply #3 on: May 07, 2007, 03:33:24 AM »
Code: [Select]
(defun test (/ e p)
  (if (setq e (entsel "\nSelect pline: "))
    (progn
      (setq
p (fix (vlax-curve-getParamAtPoint
(car e)
(vlax-curve-getClosestPointTo (car e) (cadr e))
       )
  )
e (car e)
      )
      ((lambda (a1 a2)
(list
   a1
   (- a2 a1)
)
       )
(angle
  '(0. 0.)
  (vlax-curve-getSecondDeriv e p)
)
(angle
  '(0. 0.)
  (vlax-curve-getSecondDeriv e (+ p 0.5))
)
      )
    )
  )
)