Skip to main content

useKite

Hook used to a kite.

It can be either a convex or concave kite. A convex kite is the usual kite, which every vertex points outward.

On the other hand, a concave kite, the vertex of shorter sides are point inward, which will form a v-shape or upside-down dart.

useKite({ tLength: 120, bLength: 180 });useKite({ tLength: 160, bLength: 240, isConcave: true });

Configuration

(KiteConfig | undefined) useKite accepts following configurations:

PropertyTypeDefaultDescription
tLengthnumber50Upper side length of a kite (usually the shorter side).
bLengthnumber75Lower side length of a kite (usually the longer side).
isConcavebooleanfalseIs the kite concave?

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.

tip

You can create a dart/arrow by creating a concave kite and using rotate to change its pointing direction.

note

Multiple kites can be created by 2 same side lengths, either on the "slimmer" or "squarer" side.

Right now, the implementation will always give one same kite by the same side lengths provided. We're thinking of adding an angle config to define the elevating angle of shorter side against the x-axis (horizontal line), but hold it because it may not make a great mathematical sense for creating a kite.

If you need to define that angle, please try usePolygon({ vertices }) instead, by defining the vertices yourself.

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<KiteConfig>) => voidCallback to update the configuration of the primitive.

Example

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

// A convex kite
const kite = useKite({ length: 50, length: 75 });

// A dart/arrow poiting right
const arrow = useKite({ isConcave: true, rotate: 90 });