This class describes an elliptical arc in center parameterization that is approximated using Bezier curves. It can be used to draw circles, circular arcs, ellipses and elliptical arcs, all either in clockwise or counterclockwise direction and optionally inclined in respect to the x-axis.
This graphic object is registered under the :arc key for use with the
arc = canvas.graphic_object(:arc, a: 100, b: 50, end_angle: 150) canvas.draw(arc).stroke
Length of semi-major axis which (without altering the
inclination) is parallel to the x-axis
arc = canvas.graphic_object(:arc, a: 30, b: 30) canvas.draw(arc).stroke canvas.stroke_color("red").draw(arc, a: 60).stroke
Length of semi-minor axis which (without altering the
inclination) is parallel to the y-axis
arc = canvas.graphic_object(:arc, a: 30, b: 30) canvas.draw(arc).stroke canvas.stroke_color("red").draw(arc, b: 60).stroke
Direction of arc - if
true in clockwise direction, else in counterclockwise direction
This is needed when filling paths using the nonzero winding number rule to achieve different effects.
arc = canvas.graphic_object(:arc, a: 40, b: 40) canvas.draw(arc, cx: -50).draw(arc, cx: 50). draw(arc, cx: -50, b: 80). draw(arc, cx: 50, b: 80, clockwise: true). fill(:nonzero)
The maximal number of curves used for approximating a complete ellipse.
The higher the value the better the approximation will be but it will also take longer to compute. The value should not be lower than 4. Default value is 6 which already provides a good approximation.
arc = canvas.graphic_object(:arc, cx: -50, a: 40, b: 40) arc.max_curves = 2 canvas.draw(arc) arc.max_curves = 10 canvas.draw(arc, cx: 50) canvas.stroke
Public Class Methods
Creates and configures a new elliptical arc object.
configure for the allowed keyword arguments.
Public Instance Methods
Configures the arc with
center point (
start angle of
end angle of
an inclination in respect to the x-axis of
clockwise argument determines if the arc is drawn in the counterclockwise direction (
false) or in the clockwise direction (
Any arguments not specified are not modified and retain their old value, see initialize for the inital values.
One subarray consists of
[end_point_x, end_point_y, p1: control_point_1, p2: control_point_2]
The first start point is the one returned by
start_point, the other start points are the end points of the curve before.
The format of the subarray is chosen so that it can be fed to the
Canvas#curve_to method by using array splatting.
See: ELL s3.4.1 (especially the last box on page 18)
Draws the arc on the given
If the argument
Canvas#move_to operation is executed to move the current point to the start point of the arc. Otherwise it is assumed that the current point already coincides with the start point
max_curves value, if not already changed, is set to the value of the configuration option 'graphic_object.arc.max_curves' before drawing.
Returns the point at
angle degrees on the ellipse.
Note that the point may not lie on the arc itself!