2

This sort of question is a tad bit different the normal 'how to find the intersection of two lines' via numpy. Here is the situation, I am creating a program that looks at slope stability and I need to find where a circle intersects a line.

I have two numpy arrays:

One array gives me a normal (x, y) values of an elevation profile in 2D

The other array is calculated values of coordinates (x, y) that spans the circumference of a circle from a defined centre.

I need to somehow compare the two at what approximate point does the coordinates of the circle intersect the profile line?

Here some data to work with:

circ_coords = np.array([
                        [.71,.71],
                        [0.,1.]
                       ])

linear_profile = np.array([
                           [0.,0.],
                           [1.,1.]
                         ])

I need a function that would spit out say a single or multiple coordinate values saying that based on these circular coordinates and your linear profile.. the two would intersect here.

def intersect(array1, array2):
    # stuff
    return computed_array
Uys of Spades
  • 529
  • 1
  • 7
  • 10

2 Answers2

3

You can solve it algebraically. The parametric representation of points (x,y) on the line segment between (x1,y1) and (x2,y2) is:

x=tx1+(1−t)x2 and y=ty1+(1−t)y2,

where 0≤t≤1.

If you substitute it in the equation of the circle and solve the resulting quadratic equation for t, you can test if 0≤t01≤1, i.e line segment intersets with circle. The t01 values could be than used to calculate intersection points.

Ondro
  • 997
  • 5
  • 8
2

Shapely has some cool functions. According to this post, this code should work:

from shapely.geometry import LineString
from shapely.geometry import Point

p = Point(0,0)//center
c = p.buffer(0.71).boundary//radius
l = LineString([(0.,0.), (1., 1.)])//line point
i = c.intersection(l)

Apparently here i is the array you are looking for, also, check this post too. Hope this helps.

Community
  • 1
  • 1
PseudoAj
  • 5,234
  • 2
  • 17
  • 37