FastPrepCircle Intersection in Three Dimensions

Circle Intersection in Three Dimensions

NVIDIA logoNVIDIA● HardFULLTIMEONSITE INTERVIEW
Learn

Problem statement

Each circle is a circumference in three-dimensional space. Circle i consists of points in the plane through center_i perpendicular to normal_i whose Euclidean distance from the center is exactly radius_i. A normal is not required to have length one.

Return true if the two circumferences share at least one point, and false otherwise. Count external or internal tangency and coincident circles as intersecting. Points inside a circle are not part of its circumference.

Function

circlesIntersect3D(center1: int[], normal1: int[], radius1: int, center2: int[], normal2: int[], radius2: int) → boolean

Examples

Example 1

center1 = [0, 0, 0]normal1 = [0, 0, 1]radius1 = 2center2 = [3, 0, 0]normal2 = [0, 0, 1]radius2 = 2return = true

The two coplanar circumferences cross at two points.

Example 2

center1 = [0, 0, 0]normal1 = [0, 0, 1]radius1 = 2center2 = [0, 0, 1]normal2 = [0, 0, 1]radius2 = 2return = false

The planes have equal normals but different heights, so their circles share no point.

Example 3

center1 = [0, 0, 0]normal1 = [0, 0, 1]radius1 = 1center2 = [0, 0, 0]normal2 = [0, 1, 0]radius2 = 1return = true

The planes meet on the x-axis, and both circles contain (1,0,0) and (-1,0,0).

Example 4

center1 = [0, 0, 0]normal1 = [0, 0, 1]radius1 = 1center2 = [1, 0, 1]normal2 = [1, 0, 0]radius2 = 1return = true

The planes meet on x=1, z=0. Their only shared circumference point is (1,0,0).

Constraints

  • Each center and normal has exactly three integer components.
  • Center components are in [-20, 20].
  • Normal components are in [-1, 1], and each normal is nonzero.
  • 1 <= radius1, radius2 <= 20.

More NVIDIA problems

See NVIDIA hiring insights
public boolean circlesIntersect3D(int[] center1, int[] normal1, int radius1, int[] center2, int[] normal2, int radius2) {
    // Write your code here.
}
center1[0, 0, 0]
normal1[0, 0, 1]
radius12
center2[3, 0, 0]
normal2[0, 0, 1]
radius22
expectedtrue
Checking account…