Author Topic: Converting Arc to CircularArc3d  (Read 8467 times)

0 Members and 1 Guest are viewing this topic.

MaksimS

  • Guest
Converting Arc to CircularArc3d
« on: November 30, 2007, 09:24:34 AM »
Hi all,

Could anyone point me to how to construe CircularArc3d out of Arc entity? Resulting CircularArc3d should be identical to input Arc.

Regards,
Maksim Sestic

Glenn R

  • Guest
Re: Converting Arc to CircularArc3d
« Reply #1 on: November 30, 2007, 09:37:45 AM »
Look at the last constructor in the ARX docs for AcGeCircArc3d - that should give you everything you need.

Cheers,
Glenn.

Glenn R

  • Guest
Re: Converting Arc to CircularArc3d
« Reply #2 on: November 30, 2007, 09:41:09 AM »
Or even better...the constructor that takes 3 points. You can get the startpoint, midpoint and endpoint of the arc and pass those.

MaksimS

  • Guest
Re: Converting Arc to CircularArc3d
« Reply #3 on: November 30, 2007, 09:46:07 AM »
Hi Glenn,

I'm looking at at right now and can't figure out why my resulting CircularArc3d gets rotated for certain angle around it's center :-)

I'm trying with:
Code: [Select]
Dim circArc As CircularArc3d = New CircularArc3d(arc.Center, arc.GetPlane.Normal, arc.Center.GetVectorTo(arc.StartPoint), arc.Radius, arc.StartAngle, arc.EndAngle)

This ReferenceVector, if I understand it correctly, should be defined as:
...the vector from the center of curvature to the arc start point startVector.

Regards,
Maksim Sestic

MaksimS

  • Guest
Re: Converting Arc to CircularArc3d
« Reply #4 on: November 30, 2007, 09:53:51 AM »
My first try was to use the three-parameter constructor, while getting Arc's MidPoint using:

Code: [Select]
arc.GetPointAtParameter(0.5)

It's not working for certain Arc geometries.


Glenn R

  • Guest
Re: Converting Arc to CircularArc3d
« Reply #5 on: November 30, 2007, 09:54:04 AM »
Well if you're passing the start and end angles of an existing arc, have you asked yourself what those angles are ALREADY in relation to?

What I think you will have to do is express those angles in relation to the reference vector you are constructing. So, for instance, if your ref vector is from centre point to startpoint, then your start angle would be 0...yes?

Glenn R

  • Guest
Re: Converting Arc to CircularArc3d
« Reply #6 on: November 30, 2007, 09:56:15 AM »
My first try was to use the three-parameter constructor, while getting Arc's MidPoint using:

Code: [Select]
arc.GetPointAtParameter(0.5)

It's not working for certain Arc geometries.



I wouldn't necessarily assume that 0.5 is the parameter for the mid point of the curve. Use getparameteratpoint or whatever the function is for the startpoint and endpoint, then subtract the 2 and then halve it for the parameter...that's what I would do first off anyway.

MaksimS

  • Guest
Re: Converting Arc to CircularArc3d
« Reply #7 on: November 30, 2007, 10:00:10 AM »
Glenn, you're right, that's it... :-) Sorry for my utter ignorance, I didn't have a chance to play with curves recently :-)

Glenn R

  • Guest
Re: Converting Arc to CircularArc3d
« Reply #8 on: November 30, 2007, 10:03:16 AM »
Actually, there's a startparam and endparam property on the arc - you can use ths and calculate the midpoint param. From there, use getpointatparam and you've got the 3 points for the constructor.

Glenn R

  • Guest
Re: Converting Arc to CircularArc3d
« Reply #9 on: November 30, 2007, 10:40:17 AM »
So what did you finally use? Can you post a code snippet for others?

MaksimS

  • Guest
Re: Converting Arc to CircularArc3d
« Reply #10 on: November 30, 2007, 11:28:40 AM »
I took the easier way :-)

First, get start and end parameters of an Arc:
Code: [Select]
Dim p0 As Double = arc.StartParam
Dim p1 As Double = arc.EndParam

Calculating a parameter for midpoint uses either:
Code: [Select]
Dim pM As Double = (p1 - p0) / 2
or:
Code: [Select]
Dim pM As Double = (p1 + p0) / 2

Which one to use depends on Arc geometry... but I didn't have time to find out the relation, must be some basic Arc property (I guess it's about angles). I'll check it out and post tomorrow.

Finally, construing the CircularArc3d using first constructor:
Code: [Select]
circularArc = New CircularArc3d(arc.EndPoint, arc.GetPointAtParameter(pM), arc.StartPoint)

Glenn R

  • Guest
Re: Converting Arc to CircularArc3d
« Reply #11 on: November 30, 2007, 11:48:08 AM »
Why are you passing the end, then mid, then start points? Shouldn't it be start, mid then end points?

MaksimS

  • Guest
Re: Converting Arc to CircularArc3d
« Reply #12 on: December 01, 2007, 06:51:46 AM »
Oh, those are the leftovers... It should state:

Code: [Select]
circularArc = New CircularArc3d(arc.StartPoint, arc.GetPointAtParameter(pM), arc.EndPoint)

BTW, I've found a really useful text on calculating an Arc midpoint: http://mathforum.org/library/drmath/view/54365.html

Regards,
Maksim Sestic

MaksimS

  • Guest
Re: Converting Arc to CircularArc3d
« Reply #13 on: December 01, 2007, 07:19:14 AM »
OK, along with conclusion that I really suck at trigonometry, :-) still trying to find out which Arc properties imply using either (p1 - p0) / 2 or (p1 + p0) / 2. I mean, I'll never let this peace of code end up looking like:

Code: [Select]
Dim circularArc = CircularArc3d
Dim pM As Double

Try
   pM = (p1 - p0) / 2
   circularArc = New CircularArc3d(arc.StartPoint, arc.GetPointAtParameter(pM), arc.EndPoint)
Catch ex As Autodesk.AutoCAD.Runtime.Exception
   pM = (p1 + p0) / 2
   circularArc = New CircularArc3d(arc.StartPoint, arc.GetPointAtParameter(pM), arc.EndPoint)
End Try

On the other hand, I can easily find out Arc's midpoint using a Arc.StartPoint -> Arc.EndPoint line's midpoint and an intersection between a ray normal to chord's midpoint and an Arc. But this takes up more time to calculate than processing an exception. Bah. There must be a quicker way besides this ugly exception handling and the intersection one.
« Last Edit: December 01, 2007, 07:23:58 AM by MaksimS »

MaksimS

  • Guest
Re: Converting Arc to CircularArc3d
« Reply #14 on: December 01, 2007, 07:49:55 AM »
Also an interesting read:

Code: [Select]
;; ! ****************************************************************************
;; ! GE_GetArcMidPt
;; ! ****************************************************************************
;; ! Function : Returns the midpoint of the arc which is assumed to be defined in
;; !            the Counter clockwise direction
;; ! Arguments:
;; !           'CenPt' - Center point of the arc
;; !           'rad'   - Radius of the arc
;; !           'sa'    - Start Angle
;; !           'ea'    - End   Angle
;; ! Action   : Returns a radius of the arc segment which is (sqr(D)/8H + H/2)
;; ! Updated  : October 24, 1999
;; ! (C) 1999-2004, Four Dimension Technologies, Bangalore
;; ! e-mail   : rakesh.rao@4d-technologies.com
;; ! Web      : www.4d-technologies.com
;; ! ****************************************************************************

(defun GE_GetArcMidPt ( CenPt rad sa ea / pt diff )
(if (< ea sa)
(setq ea (+ ea (* 2.0 pi)))
)
(setq
diff (- ea sa)
pt (polar CenPt (+ sa (* 0.5 diff)) rad)
)
)

And plenty of LISP (alas!) routines found here: http://www.4d-technologies.com/techcenter/index.htm