circleContains

View sourcecircleContains(position: Vector2, radius: number, point: Vector2): boolean

Tests whether a point is inside or on the boundary of a circle.

The distance is compared as squared values, so the helper avoids taking a square root. A point exactly on the circumference is contained. A radius of 0 contains only the center, while a negative radius is not rejected and behaves like the corresponding positive radius because it is squared. The vectors are read but not modified.

Examples

import { Vector2 } from '@wimaengine/math'
import { circleContains } from '@wimaengine/narrowphase'

const center = new Vector2(0, 0)
circleContains(center, 2, new Vector2(1, 1)) // true
circleContains(center, 2, new Vector2(2, 1)) // false

Parameters

NameDescriptionDefault
position

Circle center.

—
radius

Circle radius.

—
point

Point to test.

—

Returns

true when the point’s squared distance from the center is at most radius * radius.