Skip to content

shapeEdgePoint

Calculates the x/y position of a point at the edge of a shape, from the center of the shape, given a specified pixel distance and radian angle.

Given an angle in radians and a distance, returns the [x, y] offset from the shape’s center to its edge in that direction. For a circle that is simply the point at distance along the angle; angles run clockwise because y grows downward in SVG. Network and Rings use this to attach links to the edge of a node.

import {shapeEdgePoint} from "@d3plus/math";

shapeEdgePoint(0, 80, "circle");
shapeEdgePoint(Math.PI / 4, 80, "circle");
shapeEdgePoint(Math.PI / 2, 80, "circle");
shapeEdgePoint(Math.PI, 80, "circle");
shapeEdgePoint(-Math.PI / 3, 80, "circle");

For a square, distance is half the side length and the point is where the ray leaves the square, so diagonal directions reach further from the center than axis-aligned ones. Only "circle" and "square" are supported; any other shape returns null.

import {shapeEdgePoint} from "@d3plus/math";

shapeEdgePoint(0, 80, "square");
shapeEdgePoint(Math.PI / 4, 80, "square");
shapeEdgePoint(Math.PI / 2, 80, "square");
shapeEdgePoint(Math.PI, 80, "square");
shapeEdgePoint(-Math.PI / 3, 80, "square");

Parameters

import {shapeEdgePoint} from "@d3plus/math";
anglerequirednumber

The angle, in radians, of the offset point.

distancerequirednumber

The pixel distance away from the origin.

shapestringDefault circle

The shape type ("circle", "square", or "triangle").