get angle from ellipse parameters

get angle from ellipse parameters

Anonymous
適用対象外
2,089件の閲覧回数
7件の返信
メッセージ1/8

get angle from ellipse parameters

Anonymous
適用対象外

Is it possible to extract the angles of the point described by the start and end parameters after reading a dxf file, given that the semi_major, semi_minor, centre point and the start and end parameters are supplied by the dxf file.

this is the equation i am looking at,

Snippet

p(u)=(Cx+a*cos(u))*i+(Cy+b*sin(u))*j 

Snippet

Cx is the X value of the point c
Cy is the Y value of the point c
a is -(1/2 of the major axis length)
b is -(1/2 of the minor axis length)
i and j represent unit vectors in the X and Y directions 

 im not sure how or if you can rearrange to extract the angles for the start and end point, or just get the points themselves

0 件のいいね
解決済み
2,090件の閲覧回数
7件の返信
返信 (7)
メッセージ2/8

Kent1Cooper
Consultant
Consultant

In entity data for an Ellipse, the DXF 10-code value is the center, 11 is a major axis endpoint relative to the center, and 40 is the axis ratio.  So if 'edata' is the entity data for an Ellipse in the WCS, in AutoLisp terms [untested]:

 

(setq

  ctr (cdr (assoc 10 edata))

  MajorAxisRelative (cdr (assoc 11 edata))

  MajorAxisEnd1 (mapcar '+ ctr MajorAxisRelative)

  MajorAxisEnd2 (mapcar '- ctr MajorAxisRelative)

  MajorHalfAxisLength (distance ctr MajorAxisEnd1)

  MinorHalfAxisLength (* MajorHalfAxisLength (cdr (assoc 40 edata)))

  MinorAxisAngle (+ (angle '(0 0 0) MajorAxisRelative) (/ pi 2))

  MinorAxisEnd1 (polar ctr MinorAxisAngle MinorHalfAxisLength)

  MinorAxisEnd2 (polar ctr (+ MinorAxisAngle pi) MinorHalfAxisLength)

)

 

You can also get the 4 quadrant points [ends of both axes] this way in the drawing, if 'ell' is the Ellipse's entity name:

 

(setq

  MajorAxisEnd1 (vlax-curve-getStartPoint ell)

  MajorAxisEnd2 (vlax-curve-getPointAtParam ell pi)

  MinorAxisEnd1 (vlax-curve-getPointAtParam ell (/ pi 2))

  MinorAxisEnd2 (vlax-curve-getPointAtParam ell (* pi 1.5))

)

Kent Cooper, AIA
メッセージ3/8

Anonymous
適用対象外

thanks Kent,

im using c++ to read a dxf and have calculated all that info after reading, im just not sure how to extract either an angle to the start point and the end point (of a partial ellipse) or the actual x,y points themselves using the above equation which was supplied as part of the dxf documentation.

0 件のいいね
メッセージ4/8

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

…. (of a partial ellipse) ....


Ah -- a partial  one.  Are you looking for the angle that's 'u' in your first snippet?  [I don't know C++, so....]  Parameter  values for Ellipses have a nice relationship to angles in radians -- they coincide at the quadrant points, but are not the same in between them.  See >this thread<, and in particular the link from @Anonymous in Message 2.  A lot of what that deals with requires being in a drawing with a drawn Ellipse entity to work with, but if it helps you figure it out in pure DXF terms read from a .dxf file, the parameter value of the start point is in the DXF 41 entry, and of the end point in the DXF 42 entry.  They are in radian-like numbers, in relation to the major axis direction from the center.  A full Ellipse goes from Parameter 0 to 2*pi, just as a Circle does.  A partial one has to have its end parameter value greater than its start parameter value, so depending on how its start relates to that major axis direction, its end parameter value can be greater  than 2*pi.

Kent Cooper, AIA
0 件のいいね
メッセージ5/8

_gile
Consultant
Consultant

Hi,

 

Here're some quite old ones

 

;; Converts an ellipse angle into parameter
;; Arguments
,, ang   : the angle to convert
;; ratio : the minor and major axis ratio
(defun angle->param (ang ratio)
  (atan (sin ang) (* ratio (cos ang)))
)

;; Converts an ellipse parameter into angle 
;; Arguments
,, param : the parameter to convert
;; ratio : the minor and major axis ratio
(defun param->angle (param ratio)
  (atan (* ratio (sin param)) (cos param))
)

;; Gets the ellipse start angle
;; Argument
;; elst : the ellipse DXF data list
(defun getStartAngle (elst)
  (param->angle (cdr (assoc 41 elst)) (cdr (assoc 40 elst)))
)

;; Gets the ellipse end angle
;; Argument
;; elst : the ellipse DXF data list
(defun getEndAngle (elst)
  (param->angle (cdr (assoc 42 elst)) (cdr (assoc 40 elst)))
)


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 件のいいね
メッセージ6/8

Anonymous
適用対象外

@Kent1Cooperyep (u) is either start(41) or end(42) parameters depending on which one your trying to solve.

 

@_gilecheers for the snippets, i a m ignorant when it comes to auto lisp.  Your 2nd function looks like the one im after, if i can work out the angle associated with the param(u) everything else is easy enough.  Please correct me if im wrong but the body of the function reads.

 

angle in degrees = atan ( ratio x sin( param ) x cos( param) ).

 

what is the leading "*" in

* ratio

 is it auto lisps version of a pointer

0 件のいいね
メッセージ7/8

_gile
Consultant
Consultant
解決済み

@Anonymous  a écrit :

angle in degrees = atan ( ratio x sin( param ) x cos( param) ).


More accurately:

angle in radians = atan ( ratio x sin( param ) ) cos( param) )

I do not know C++, but with C# it should be:

angle = Math.Atan2(ratio * Math.Sin(param), Math.Cos(param))

 


@Anonymous  a écrit :

what is the leading "*" in

* ratio

 is it auto lisps version of a pointer


It is the multiplication operator. LISP uses a prefixed syntax: (* a b) stands for: a * b



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

メッセージ8/8

Anonymous
適用対象外

@_gile,

thanks mate your a legend. Had been racking my brains for a couple of arvos.

It seems that using the equation you supplied gives the angle in radians from the "semi_major" point or the point that the ellipse is defined by the major axis, and not relative to a co-ordinate system.

 

this is the equation to give the angle from the semi major point to the start point of the ellipse (parameter 41). In the ellipse i tried the ellipse was rotated at 45 deg.

in c#

Snippet

double angle_rad = Math.Atan2_minor_major_ratio * Math.Sin( start_param ), Math.Cos( start_param ) );

which is -45 degrees, so 45-45 = 0 which is correct for the ellipse the end parameter also checks out.  will see if it works for all cases.

 

Fyi c# and c++ use of operators is almost identical, except c# doesn't use & or (*)pointer as its a higher level language.

 

once again thanks for your help.

0 件のいいね