Main Content

linecirc

Find intersection of line and circle in Cartesian coordinates

Description

[xout,yout] = linecirc(slope,intercpt,centerx,centery,radius) finds the intersection of a line with the specified slope and intercept and a circle with the specified center and radius, in Cartesian coordinates.

example

Examples

collapse all

Find the intersection of the line y=2x-1 and a circle with its center at (3, 4) and a radius of 5.

[xout,yout] = linecirc(2,-1,3,4,5)
xout = 1×2

    4.8271    0.3729

yout = 1×2

    8.6542   -0.2542

Find the intersection of the line x=-1 and a circle with its center at (3, 4) and a radius of 5.

[xout,yout] = linecirc(Inf,-1,3,4,5)
xout = 1×2

    -1    -1

yout = 1×2

     7     1

Input Arguments

collapse all

Slope of the line, specified as a numeric scalar or Inf. Specify Inf when the line is vertical.

Intercept of the line, specified as a numeric scalar.

  • When slope is a numeric scalar, this argument is the y-intercept of the line.

  • When slope is Inf, this argument is the x-intercept of the line.

x-coordinate of the center of the circle, specified as a numeric scalar.

y-coordinate of the center of the circle, specified as a numeric scalar.

Radius of the circle, specified as a positive scalar.

Output Arguments

collapse all

x-coordinates of the intersections, returned as a two-element vector.

  • When the line is tangent to the circle, the elements of the vector are equal.

  • When the line does not intersect the circle, both elements are NaN.

y-coordinates of the intersections, returned as a two-element vector.

  • When the line is tangent to the circle, the elements of the vector are equal.

  • When the line does not intersect the circle, both elements are NaN.

Version History

Introduced before R2006a

See Also

Functions