ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Drawing an ARC (with the option of color fill)
Posted by icm63 on Jan-16-2022 02:03
Attachments:
If I have two points how can I draw an ARC on a XYChart

With the option of fill the semi circle with color.
Arc_SemiCircle.png

  Re: Drawing an ARC (with the option of color fill)
Posted by Peter Kwan on Jan-18-2022 02:58
Hi icm63,

In ChartDirector, you can draw an arc by using the DrawArea.arc API:

https://www.advsofteng.com/doc/cdnet.htm#DrawArea.arc.htm

It is mathematically impossible to uniquely determine an arc with just two points. There are infinite number of arcs that can pass through any 2 points. You need 3 points or an additional constraint to uniquely determine the arc.

With sufficient information, you should be possible to derive the equation of the arc from the points and/or constraints. You can then determine the information necessary to use the ChartDirector API to draw the arc, which are the coordinate of the center and the starting and ending angles.

Regards
Peter Kwan

  Re: Drawing an ARC (with the option of color fill)
Posted by icm63 on Jan-18-2022 03:07
Thanks

Point1: Pt1.x, Pt1.y
Point2: Pt2.x, Pt2.y
Point3: Pt1.x + Pt2.x, Pt1.y

Show do the above fit into the function parameters?
https://www.advsofteng.com/doc/cdnet.htm#DrawArea.arc.htm

Any way to COLOR in the ARC (semi circle)

  Re: Drawing an ARC (with the option of color fill)
Posted by Peter Kwan on Jan-18-2022 13:08
Hi icm63,

Would you mind to clarify what do you mean by "arc"? I assume you mean part of the perimeter of a circle. In this case, in your first message, the example in the top-left is clearly not an arc. In that example, starting from pt1, the arc should flow in the top-left direction away from pt2, then curve back to the right to join pt2.

If the above is exactly what you mean (that an "arc" is part of a circle), and you want to define it with 3 points lying on the arc. With the 3 points, you should be able to calculate the center of the circle easily. With the center determined, you can calculate the angles using trigonometry. With the center and angles known, you can ask ChartDirector to draw the arc.

There should be a lot math tutorial in the internet on how to calculate the center given 3 points. (You can try to search "center of circle given three points".)

For "coloring the arc", I assume you mean to color some region bound by the arc. There are two common meaning of what is the region bounded by the arc. It can be a circle sector or a circle segment. For a circle sector, you can use DrawArea.sector. For the circle segment, you would be compute many points on the arc (eg. one point per 3 degrees) to approximate the arc as a polygon, and use DrawArea.polygon to fill it.

If by "arc", you do not mean "part of a circle", you would need to define what it means in order to draw it. In some cases, it may just mean "any curve that looks nice". If this is the curve, you can draw it as a spline curve using XYChart.addSplineLayer.

Regards
Peter Kwan

  Re: Drawing an ARC (with the option of color fill)
Posted by icm63 on Jan-19-2022 00:38
Thanks

All sorted