Method: HexaPDF::Content::Canvas#arc
- Defined in:
- lib/hexapdf/content/canvas.rb
#arc(cx, cy, a:, b: a, start_angle: 0, end_angle: 360, clockwise: false, inclination: 0) ⇒ Object
:call-seq:
canvas.arc(cx, cy, a:, b: a, start_angle: 0, end_angle: 360, clockwise: false, inclination: 0) => canvas
Appends an elliptical arc to the path and returns self. The endpoint of the arc becomes the new current point.
cx-
x-coordinate of the center point of the arc
cy-
y-coordinate of the center point of the arc
a-
Length of semi-major axis
b-
Length of semi-minor axis (default:
a) start_angle-
Angle in degrees at which to start the arc (default: 0)
end_angle-
Angle in degrees at which to end the arc (default: 360)
clockwise-
If
truethe arc is drawn in clockwise direction, otherwise in counterclockwise direction (default: false). inclination-
Angle in degrees between the x-axis and the semi-major axis (default: 0)
If a and b are equal, a circular arc is drawn. If the difference of the start angle and end angle is equal to 360, a full ellipse (or circle) is drawn.
If there is no current path when the method is invoked, a new path is automatically begun.
This arc does not start from the current point (#current_point). If this functionality is needed, use #draw together with GraphicObject::EndpointArc.
Since PDF doesn’t have operators for drawing elliptical or circular arcs, they have to be approximated using Bezier curves (see #curve_to). The accuracy of the approximation can be controlled using the configuration option ‘graphic_object.arc.max_curves’.
Examples:
#>pdf
canvas.arc(50, 150, a: 10) # Circle with radius 10
canvas.arc(100, 150, a: 10, b: 5) # Ellipse with radii 10 and 5
canvas.arc(150, 150, a: 10, b: 5, inclination: 45) # The above ellipse inclined 45 degrees
canvas.stroke
# Circular and elliptical arcs from 30 degrees to 160 degrees
canvas.stroke_color("hp-blue")
canvas.arc(50, 100, a: 10, start_angle: 30, end_angle: 160)
canvas.arc(100, 100, a: 10, b: 5, start_angle: 30, end_angle: 160)
canvas.stroke
# Arcs from 135 degrees to 30 degrees, the first in counterclockwise direction (i.e. the
# big arc), the other in clockwise direction (i.e. the small arc)
canvas.stroke_color("hp-orange")
canvas.arc(50, 50, a: 10, start_angle: 135, end_angle: 30)
canvas.arc(100, 50, a: 10, start_angle: 135, end_angle: 30, clockwise: true)
canvas.stroke
See: #arc, #circle, #ellipse, GraphicObject::Arc, GraphicObject::EndpointArc
1385 1386 1387 1388 1389 1390 1391 |
# File 'lib/hexapdf/content/canvas.rb', line 1385 def arc(cx, cy, a:, b: a, start_angle: 0, end_angle: 360, clockwise: false, inclination: 0) arc = GraphicObject::Arc.configure(cx: cx, cy: cy, a: a, b: b, start_angle: start_angle, end_angle: end_angle, clockwise: clockwise, inclination: inclination) arc.draw(self) self end |