Skip to main content

useArc

Hook used to create arc of a circle.

useArc({ angle: 120 });useArc({ angle: 235, rotate: -108 });

Configuration

note

useArc will draw an arc counter-clockwise, starting from the right centre position (just like how trigo normally works).

If you wish to create an arc facing to other side, please use rotate.

(ArcConfig | undefined) useArc accepts following configurations:

PropertyTypeDefaultDescription
radiusnumber100Radius of the arc.
anglenumber60Angle of the arc, in degrees.

extends Primitive Configuration

(PrimitiveConfig) Base configurations for all primitives.

PropertyTypeDefaultDescription
scalenumber | Vertex1Scaling factor of the primitive. If Vertex is provided, it will scale x and y dimension accordingly (optional).
rotatenumber0Rotation of the primitive, in degrees, in clockwise manner (optional).
positionVertex{ x: 0, y: 0 }Moving distance away from the primitive drawing centre. By default, primitive will start drawing in origin (0, 0) (optional).
info

scale, rotate and position can be considered as transformation of polygon after drawn, where position can be considered as transform: translate of css to the primitive.

The polygon will first be scaled, then rotated and lastly, translated.

Returns

(Primitive) All primitive return the following properties:

PropertyTypeDescription
verticesVertex[]Vertices of the primitive.
edgesEdge[]Edges of the primitive.
facesFace[]Faces of the primitive.
centroidVertexCentroid (geometric centre) of primitive.
boundingBoxBoundingBoxSpace constraint of the primitive, with properties x, y, width and height.
svgPathstringSVG path representing the shape of the primitive.
drawToCanvas(ctx: CanvasRenderingContext2D) => voidCallback that draws the primitive to a canvas context.
modifyConfig(newConfig: Partial<ArcConfig>) => voidCallback to update the configuration of the primitive.

Example

import { useArc } from "react-use-polygon";

const arc = useArc({ radius: 80, angle: 45, rotate: 30 });