Author Topic: entmake vs. vla-addellipse  (Read 2902 times)

0 Members and 1 Guest are viewing this topic.

hmspe

  • Bull Frog
  • Posts: 362
entmake vs. vla-addellipse
« on: February 24, 2013, 11:07:24 AM »
I am getting different linework when I try to entmake an elliptical arc compared to using vla-addellipse when I pass identical parameters.  Can anyone can provide any insight as to why?         

Code: [Select]
[font=courier](defun c:test ()
  (setq angle1           2.57219967
        angle2           2.78994653
        ellipse_center   (list 22.3978 21.082 0.0)
        major_axis_point (list -12.6885 -50.7174 0.0)
        axis_ratio       0.310108
  )
  (setq space (vla-get-modelspace
                (vla-get-activedocument
                  (vlax-get-acad-object)
                )
              )
  )
  (setq obj (vla-AddEllipse space
                            (vlax-3d-point ellipse_center)
                            (vlax-3d-point major_axis_point)
                            axis_ratio
            )
  )
  (vla-put-startangle obj angle1)
  (vla-put-endangle obj angle2)
  (entmakex (list (cons 0 "ELLIPSE")
                  (cons 100 "AcDbEntity")
                  (cons 100 "AcDbEllipse")
                  (cons 6 "Continuous")
                  (cons 10 ellipse_center)
                  (cons 11 major_axis_point)
                  (cons 40 axis_ratio)
                  (cons 41 angle1)
                  (cons 42 angle2)
            )
  )     
)

[/font]
"Science is the belief in the ignorance of experts." - Richard Feynman

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: entmake vs. vla-addellipse
« Reply #1 on: February 24, 2013, 12:08:19 PM »
Hi,

41 and 42 ellipse DXF codes aren't related to start and end angles but start and end parameters.

Have a look at  the "parameter" chapter in the Ellipse command help.

The parametric vector equation is:
param(u) = Center + majorAxis * cos(u) + minorAxis * sin(u)

IOW:
tan(StartAngle) = ratio * tan(StratParam)
Speaking English as a French Frog

ribarm

  • Gator
  • Posts: 3257
  • Marko Ribar, architect
Re: entmake vs. vla-addellipse
« Reply #2 on: February 24, 2013, 12:33:37 PM »
Take look at your example closely... Both are correct, only difference is that dxf41 and dxf42 represent angles in radians of parent circle used to construct elliptical arc with projection of main ellipse axis from main circle angles back to ellipse... On the other hand (vla-put-(start)(end)angle) function takes explicitly that angle from parent circle and doesn't project it back to ellipse - it just extends them to elliptical arc...

Attached your example as *.dwg...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: entmake vs. vla-addellipse
« Reply #3 on: February 24, 2013, 02:47:30 PM »
Great diagram gile  :-)

Though, I think your link to the help section is broken, here is another link to the documentation describing the ellipse parameter.

Also, the diagram on this page may help to explain.

hmspe

  • Bull Frog
  • Posts: 362
Re: entmake vs. vla-addellipse
« Reply #4 on: February 24, 2013, 03:20:55 PM »
Thanks to all.  It makes sense now.

Martin
"Science is the belief in the ignorance of experts." - Richard Feynman

Lee Mac

  • Seagull
  • Posts: 12912
  • London, England
Re: entmake vs. vla-addellipse
« Reply #5 on: February 24, 2013, 05:57:27 PM »
FWIW, here are my functions for converting between points and parameters for an ellipse:

Code - Auto/Visual Lisp: [Select]
  1. ;; Ellipse Parameter -> Point  -  Lee Mac
  2. ;; Returns the UCS point for the given ellipse parameter
  3. ;; dxf  -  Ellipse DXF data (DXF groups 10, 11 & 40)
  4. ;; par  -  Ellipse parameter
  5.  
  6. (defun LM:param->point ( dxf par / a b m r )
  7.     (setq m (trans (cdr (assoc 11 dxf)) 0 1)
  8.           a (distance '(0.0 0.0) m)
  9.           b (* (cdr (assoc 40 dxf)) a)
  10.           r (angle '(0.0 0.0) m)
  11.     )
  12.     (mapcar '+ (trans (cdr (assoc 10 dxf)) 0 1)
  13.         (mxv (list (list (cos r) (- (sin r))) (list (sin r) (cos r)))
  14.              (list (* a (cos par)) (* b (sin par)))
  15.         )
  16.     )
  17. )
  18.  
  19. ;; Point -> Ellipse Parameter  -  Lee Mac
  20. ;; Returns the ellipse parameter for the given point
  21. ;; dxf  -  Ellipse DXF data (DXF groups 10, 11 & 40)
  22. ;; pt   -  UCS Point on Ellipse
  23.  
  24. (defun LM:point->param ( dxf pt / a b m r u x y )
  25.     (setq m (trans (cdr (assoc 11 dxf)) 0 1)
  26.           a (distance '(0.0 0.0) m)
  27.           b (* (cdr (assoc 40 dxf)) a)
  28.           r (angle '(0.0 0.0) m)
  29.     )
  30.     (mapcar 'set '(x y)
  31.         (mxv (list (list (cos r) (sin r)) (list (- (sin r)) (cos r)))
  32.              (mapcar '- pt (trans (cdr (assoc 10 dxf)) 0 1))
  33.         )
  34.     )
  35.     (if (< y 0)
  36.         (setq u (- (+ pi pi) (acos (/ x a))))
  37.         (setq u (acos (/ x a)))
  38.     )
  39.     (rem (+ pi pi u) (+ pi pi))
  40. )
  41.  
  42. ;; Matrix x Vector  -  Vladimir Nesterovsky
  43. ;; Args: m - nxn matrix, v - vector in R^n
  44.  
  45. (defun mxv ( m v )
  46.     (mapcar '(lambda ( r ) (apply '+ (mapcar '* r v))) m)
  47. )
  48.  
  49. ;; ArcCosine  -  Lee Mac
  50. ;; Args: -1 <= x <= 1
  51.  
  52. (defun acos ( x )
  53.     (if (<= -1.0 x 1.0)
  54.         (atan (sqrt (- 1.0 (* x x))) x)
  55.     )
  56. )