I want to export geometry of extrusion. How I need to retrieve startAngle, endAngle of a Arc
Here is My code:
.... Extrusion extrusion = elem as Extrusion; CurveArrArray curveArrArray = extrusion.Sketch.Profile; foreach (CurveArray curveArr in curveArrArray) { .... foreach (Curve curve in curveArr) { if (curve is Arc) { Arc arc = curve as Arc; // get center point XYZ centerpoint = arc.Center; // get start and end angle. what is wrong? double startAngle = arc.GetEndParameter(0); double endtAngle = arc.GetEndParameter(1); } } }
What is wrong? How can I fix it?
Thanks
Solved! Go to Solution.
Solved by jeremytammik. Go to Solution.
Solved by aignatovich. Go to Solution.
Dear Nam,
Thank you for your query.
The GetEndParameter method returns the raw parameter value at the start or end of this curve:
http://www.revitapidocs.com/2018.1/0f4b2c25-35f8-4e3c-c71a-0d41fb6935ce.htm
You don't know what this parameter value represents.
As far as I can tell from the documentation, the arc does not provide the angle values directly.
To determine them, I would suggest retrieving the start and end point and calculating their angles to the centre point yourself, e.g., using their AngleOnPlaneTo method:
http://www.revitapidocs.com/2018.1/417e2c71-f806-746c-c638-d54d220f8476.htm
I hope this helps.
Best regards,
Jeremy
Hey nam_vt,
I remember a post of Revitalizer (?) explaining that indeed the GetEndParameter gives you the start and end angle of an Arc, multiplied by the radius (ie the real length of the arc).
But when I try it in Revit I find only the angle of the Arc (not multiplied by the radius).
Still, you have not explained what is wrong for you...
Cheers!
Benoit
Dear nam_vt,
GetEndParameter method does not return angle value.
If you want to get the angle, you need to calculate manually.
please see codes below:
XYZ center = arc.Center; XYZ dir0 = (arc.GetEndPoint(0) - center).Normalize(); XYZ dir1 = (arc.GetEndPoint(1) - center).Normalize(); double startAngle = dir0.AngleOnPlaneTo(arc.XDirection, arc.Normal); double endAngle = dir1.AngleOnPlaneTo(arc.XDirection, arc.Normal);
Hi all!
It seems, that GetEndParameter method returns correct values, the same as @JimJia suggested, so it is actually the angle on plane with Arc.Normal and origin equal to arc.Center between arc.XDirection and endpoint. The difference is that you can get arc.GetEndParameter(1) == 2.0*Math.PI value instead of zero. It is also correct, the first parameter should be less, than the last one.
Thanks. How can I detect arc from startAngle to EndAngle is clockwise or anti-clockwise?
Maybe:
if (EndAngle- StartAngle< Pi)
{
if ( arc.length< Pi.radius) => anti-clockwise;
else clockwise ?
}
Yes, GetEndParameter return the angle on plane with Arc.Normal and origin equal to arc.Center between arc.XDirection and endpoint. not angle to sketch = extrusion.Sketch.SketchPlane.GetPlane();
double angle1 = arc.Normal.AngleTo(sketch); return the angle between the two vectors between 0 and PI
how to I calc StarAngle, EndAngle of Arc with sketch plane , not Arc plane
XYZ P45 = new XYZ(Math.Sqrt(2) / 2, Math.Sqrt(2) / 2, 0);
XYZ P60 = new XYZ(0.5, Math.Sqrt(3) / 2, 0);
XYZ P30 = new XYZ(Math.Sqrt(3) / 2, 0.5, 0);
double Angle60To45= P60.AngleTo(P45); // return Pi/12 radian --15 degree
double Angle30To45= P30.AngleTo(P45); // return Pi/12 radian -- 15 degree
I expect to receive Pi/12 with Angle60To45 and -Pi/12 with Angle30To45 how can I do?
Thanks
Dear Nam,
AngleTo returns the shortest possible non-negative angle, measuring in whatever 3D plane gives the smallest angle.
This angle will always be positive (or zero).
If you want to obtain a negative angle, you need to specify a plane in space to force the measurement to go in one specific direction.
This can be achieved using the AngleOnPlaneTo method:
http://www.revitapidocs.com/2018.1/417e2c71-f806-746c-c638-d54d220f8476.htm
Please always study the Revit API documentation carefully before asking too many questions.
Thank you!
Cheers,
Jeremy
This seems like the best topic to respond to regarding Arc.GetEndParameter and arc angles.
What I've noticed recently is that the actual parameters of an arc can be far greater than 2 * pi, so how does this happen?
If you draw a detail arc and drag the ends of the arc one at a time around the circumference the parameter values will accumulate and become greater than 2 pi after (1 cycle). They don't reset, you can effectively wind up the arc parameters this way (I discovered parameter numbers reaching 1000 degrees). We could not create arcs otherwise since the creation method enforces p0 must be less than p1 and arcs are drawn anti clockwise. When you cross 2 pi / 0 boundary you need p1 not to be starting again from 0 otherwise it would be less than p0 on the other side of the boundary.
So as @JimJia noted they are not reliable for arc start end angles (or are if the ends have not been manipulated in such a way). However in a way you can get back to the correct angles between 0 and 2 x pi (since each rotation is a multiple of 2 x pi) i.e.
Divide by 2 * pi,
Deduct integer part of result
If this is less than 0 add 1 (to negative number)
Multiply by 2 * pi
I'm not sure why you would need to do this however.
Other thing I would note is always use Arc.XDirection and Arc.Normal with AngleOnPlaneTo (rather than assuming) since arc can be flipped or rotated.
Also above was related to winding the arc ends around the circumference in an anti-clockwise direction to increase parameter values.
If user drags ends around in a clockwise direction then you get negative values for the parameters. Takes less movement from original by user to go into negative domain so this is more likely to be seen perhaps.