Alexandre B A Villares


Arc, tangents & Bezier studies

sketch_2020_09_26a

from sketch-a-day project, sketch_2020_09_26a

This repository contains the product of my studies trying to work with arcs, bezier approximations of arcs and tangents. I have added just a few new ideas here, you can look at the findings & previous studies I moved into the PRIOR_ART folder, and I tried to attribute stuff with links. Feel free to open an issue if you have a question.

The functions presented here can be found at arcs.py, they were made initially on Processing Python mode and now work with py5. Most will work with pyp5js or with the modified pyp5js/py5mode too, and I have ported b_arc for Processing Java and p5js.

You are welcome to help porting more stuff!

Please note that the most recent (and maybe unstable?) version of the Python functions shown here, with support only for py5, are kept at this other repository: github.com/villares/villares, on arcs_helper.py.

Consider supporting my work with a small donation (links on the footer).

Bezier approximation of an arc

Processing PShape insfrastructure and py5’s Py5Shape, that depends on it, do not contain fuctions for embeding an arc in a larger polyline shape. The b_arc function provided here can be used inside begin_shape()/end_shape() as a kind of “arc_vertex” (which doesn’t exist). It follows mostly the Processing/py5 arc signature, but does not include PIE and CHORD modes. You can find demos at:

x, y, w, h, start_angle, end_angle = 75, 100, 100, 100, 0, PI + QUARTER_PI
# Standalone arc replacement
b_arc(x, y, w, h, start_angle, end_angle)

# mode=2 for use inside begin_shape/end_shape
x += 125
begin_shape()
b_arc(x, y, w, h, start_angle, end_angle, mode=2) 
end_shape(CLOSE)
x += 125
begin_shape()
b_arc(x, y, w, h, start_angle, end_angle, mode=2)
vertex(x, y)
end_shape(CLOSE)

More arcs, the p_arc function, and the first shapes with tangents

Other functions based on b_arc, and a polygonal approximation called p_arc can be found on arcs.py and arc_helpers.py:


# default var_bar & bar with b_arc
var_bar(50, 165, 350, 315, 40, 0) # by default arc_func=b_arc
bar(50, 55, 350, 255, thickness=60, shorter=mouse_x)
var_bar(50, 255, 50 + mouse_x * 0.6, 255 + mouse_x * 0.25, 20, 40)
 
# var_bar & bar with p_arc
var_bar(50, 165, 350, 315, 40, 0, arc_func=p_arc, num_points=6)
bar(50, 55, 350, 255, thickness=60,
    shorter=mouse_x, arc_func=p_arc, num_points=3)
var_bar(50, 255,
        50 + mouse_x * 0.6, 255 + mouse_x * 0.25, 20, 40,
        arc_func=p_arc, num_points=8)
 
# var_bar_pts
pts1 = var_bar_pts(50, 165, 350, 315, 40, 0, num_points=6)
pts2 = var_bar_pts(50, 55, 350, 255, 30, 30,
                   shorter=mouse_x, num_points=3)
pts3 = var_bar_pts(50, 255,
                   50 + mouse_x * 0.6, 255 + mouse_x * 0.25, 20, 40,
                   num_points=8)
stroke_weight(5)
for px, py in pts1 + pts2 + pts3:
    point(px, py)

The full code for this interactive demo can be found here and it also runs on the browser with pyp5js/py5mode here!

Filleted polygons and nice shapes that can wrap circles

Perhaps the bigest motivation for starting the studies in this repository, next, we have some functions that povide continous poly-based shapes with tangent arcs.


If you like this, support my work with a small donation! Here, with Wise or at LiberaPay.