Skip to content

Add arcVertex() for creating arcs with beginShape()/endShape() #6459

Open
@GregStanton

Description

@GregStanton

Increasing Access

This feature increases access in two main ways:

  1. It addresses an inconsistency that may be an obstacle for beginners.
  2. It allows the user to perform common tasks with less mathematical knowledge.

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build Process
  • Unit Testing
  • Internalization
  • Friendly Errors
  • Other (specify if possible)

Feature request details

Proposal

Add arcVertex() to the set of vertex functions in p5, to address a limitation of beginShape()/endShape().

The problem

Two of p5’s curve-vertex pairs are incomplete. In the table below, asterisks indicate missing items.

p5 curve p5 vertex
line/polyline line() vertex()
quadratic Bézier quadratic()* quadraticVertex()
cubic Bézier bezier() bezierVertex()
Catmull-Rom spline curve() curveVertex()
circular/elliptical arc arc() arcVertex()*

Of the missing items, arcVertex() is the most important. Arcs are the only type of SVG subpaths not supported by p5’s beginShape()/endShape(). Without them, p5's most powerful shape-making feature cannot make some of the most basic shapes (e.g. lines and Bézier curves can only approximate circles). This leads to complications for both users and developers.

The solution

Provide a new function called arcVertex() based on SVG’s arc command. Applications include the following:

  • Rounded corners: Allow users to round corners of polygons (not just rectangles) without approximations.
  • Shape objects: Retain exact data for built-in and custom shapes in a common format usable by beginShape()/endShape().
  • SVG paths: Work with SVG paths by translating SVG path commands directly to p5 vertex commands.

Specification of arcVertex()

The following may serve as a draft reference page and usage tutorial.

Description

Used to draw an arc along a circle or ellipse (oval), from one vertex (point) to another. The arc may be drawn along any ellipse, even one that’s been rotated. (If the ellipse is too small to connect the two vertices, its size is automatically adjusted.)

The first vertex is specified with vertex(). The second vertex is specified with arcVertex(). Both are specified within beginShape() and endShape(), with no parameter passed to beginShape().

The arc itself is specified by indicating the shape and rotation of the ellipse (w, h, and angle), together with its type (MINOR or MAJOR) and its direction (COUNTERCLOCKWISE or CLOCKWISE).

If DEGREES is passed to angleMode(), angle may be specified in degrees; otherwise, angle should be specified in radians. If RADIUS is passed to ellipseMode(), the shape parameters are interpreted as half of the width and half of the height: arcVertex(20, 50, ... ) results in an arc drawn along an ellipse of width 40 and height 100.

Usage

beginShape();
vertex(x1, y1);
arcVertex(w, h, angle, type, direction, x2, y2);
endShape();

Syntax

arcVertex(w, h, angle, type, direction, x2, y2)

Parameters

Name Description
w Number: width of ellipse along which arc is drawn
h Number: height of ellipse along which arc is drawn
angle Number: angle by which ellipse is rotated relative to x-axis
type Constant: either MAJOR or MINOR
direction Constant: either COUNTERCLOCKWISE or CLOCKWISE
x2 Number: x-coordinate of ending vertex
y2 Number: y-coordinate of ending vertex

Tutorial

arcVertex tutorial

Related issues

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions