Scipy.spatial.Voronoi: How do I know where the ray crosses a given line?

Good afternoon everyone

I have the following code segment:

import numpy as np
from random import randint
import matplotlib.pyplot as plt
from scipy.spatial import Voronoi, voronoi_plot_2d

NUM_OF_POINTS = 20

points = []
for i in range (0, NUM_OF_POINTS):
    points.append([randint(0, 500), randint(0, 500)]) 

points = np.array(points)
vor = Voronoi(points)
voronoi_plot_2d(vor)
plt.show()

This creates Voronoi graphics, such as: arbitrary Voronoi diagram

My goal is to find where the "rays" (lines coming out of the chart, dashed or solid) intersect with this line (for example, x = 500). How can i do this?

I have already tried using the ridge_verticeslist in the object Voronoi, however, these "rays" are associated with only one vertex in the list, so I can not determine the linear equation.

Edit:

My ultimate goal is to find the points that intersect with these boundaries for a given cell of edges, taking into account the boundaries of the plane. For example, given the edge cell in the upper left corner and the borders y = -50 and x = 525, I would find points marked in red by X.

example case

, - , .

.

+4
1
  • , x y.

  • , , , , "" ( ). - (x1, y_1) (x_2, y_2), (x*, y*), :

(1) (x*-x_1)^2 + (y*-y_1)^2 = d^2

(2) (x*-x_2)^2 + (y*-y_2)^2 = d^2

x*, y*, . (x* y* d). , y*, x*:

x* = ((y*-y_1)^2 - (y*-y_2)^2 + x_1^2 - x_2^2) / (2 * (x_1 - x_2))


, , (x_1, y_1) (x_2, y_2) ?

:

(1) (n * (n-1)/2 , ), x* y*, . (x_1, y_1), (x_2, y_2), (x*, y*) .

(2) (x*, y*) 2 ( scipy.spatial.KDTree). (x_1, y_1) (x_2, y_2), (x*, y*).

KD- - O (n log n) (IIRC), O (n ^ 2) .

+2

Source: https://habr.com/ru/post/1676608/


All Articles