TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: hmspe on February 24, 2013, 11:07:24 AM

Title: entmake vs. vla-addellipse
Post by: hmspe 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]
Title: Re: entmake vs. vla-addellipse
Post by: gile 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 (http://ocs.autodesk.com/ACD/2010/ENU/AutoCAD 2010 User Documentation/index.html?url=WS1a9193826455f5ffa23ce210c4a30acaf-6f11.htm,topicNumber=d0e64588).

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

IOW:
tan(StartAngle) = ratio * tan(StratParam)
Title: Re: entmake vs. vla-addellipse
Post by: ribarm 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...
Title: Re: entmake vs. vla-addellipse
Post by: Lee Mac on February 24, 2013, 02:47:30 PM
Great diagram gile  :-)

Though, I think your link to the help section is broken, here (http://www.autodesk.com/techpubs/autocad/acad2000/dxf/ellipse_command39s_parameter_option_dxf_06.htm) is another link to the documentation describing the ellipse parameter.

Also, the diagram on this page (http://en.wikipedia.org/wiki/Eccentric_anomaly) may help to explain.
Title: Re: entmake vs. vla-addellipse
Post by: hmspe on February 24, 2013, 03:20:55 PM
Thanks to all.  It makes sense now.

Martin
Title: Re: entmake vs. vla-addellipse
Post by: Lee Mac 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. )