mirror of
https://github.com/enzet/map-machine.git
synced 2025-05-24 14:36:25 +02:00
Issue #45: fix line intersection.
Use infinite lines to find intersection point.
This commit is contained in:
parent
edf75ff53c
commit
b15029a07e
2 changed files with 21 additions and 25 deletions
|
@ -6,11 +6,10 @@ from typing import List
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import svgwrite
|
import svgwrite
|
||||||
from shapely.geometry import LineString, Point
|
|
||||||
|
|
||||||
from roentgen.constructor import Road
|
from roentgen.constructor import Road
|
||||||
from roentgen.flinger import Flinger
|
from roentgen.flinger import Flinger
|
||||||
from roentgen.vector import angle, turn_by_angle, norm
|
from roentgen.vector import angle, turn_by_angle, norm, Line
|
||||||
from roentgen.osm_reader import OSMNode
|
from roentgen.osm_reader import OSMNode
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,7 +162,7 @@ class RoadPart:
|
||||||
]
|
]
|
||||||
drawing.add(drawing.path(path_commands, fill="#CCCCCC"))
|
drawing.add(drawing.path(path_commands, fill="#CCCCCC"))
|
||||||
|
|
||||||
self.draw_entrance(drawing, False)
|
# self.draw_entrance(drawing, False)
|
||||||
|
|
||||||
def draw_entrance(self, drawing: svgwrite.Drawing, is_debug: bool):
|
def draw_entrance(self, drawing: svgwrite.Drawing, is_debug: bool):
|
||||||
path_commands = [
|
path_commands = [
|
||||||
|
@ -210,26 +209,21 @@ class Intersection:
|
||||||
next_index: int = 0 if index == len(self.parts) - 1 else index + 1
|
next_index: int = 0 if index == len(self.parts) - 1 else index + 1
|
||||||
part_1 = self.parts[index]
|
part_1 = self.parts[index]
|
||||||
part_2 = self.parts[next_index]
|
part_2 = self.parts[next_index]
|
||||||
line_1 = LineString(
|
line_1 = Line(
|
||||||
[
|
part_1.point_1 + part_1.right_vector,
|
||||||
part_1.point_1 + part_1.right_vector,
|
part_1.point_2 + part_1.right_vector,
|
||||||
part_1.point_2 + part_1.right_vector,
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
line_2 = LineString(
|
line_2 = Line(
|
||||||
[
|
part_2.point_1 + part_2.left_vector,
|
||||||
part_2.point_1 + part_2.left_vector,
|
part_2.point_2 + part_2.left_vector,
|
||||||
part_2.point_2 + part_2.left_vector,
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
a = line_1.intersection(line_2)
|
a = line_1.get_intersection_point(line_2)
|
||||||
if isinstance(a, Point):
|
part_1.right_connection = a
|
||||||
part_1.right_connection = np.array((a.x, a.y))
|
part_2.left_connection = a
|
||||||
part_2.left_connection = np.array((a.x, a.y))
|
part_1.update()
|
||||||
part_1.update()
|
part_2.update()
|
||||||
part_2.update()
|
|
||||||
|
|
||||||
def draw(self, drawing: svgwrite.Drawing, is_debug: bool):
|
def draw(self, drawing: svgwrite.Drawing, is_debug: bool = False):
|
||||||
"""
|
"""
|
||||||
Draw all road parts and intersection.
|
Draw all road parts and intersection.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -21,10 +21,12 @@ def turn_by_angle(vector: np.array, angle: float):
|
||||||
"""
|
"""
|
||||||
Turn vector by an angle.
|
Turn vector by an angle.
|
||||||
"""
|
"""
|
||||||
return np.array((
|
return np.array(
|
||||||
vector[0] * np.cos(angle) - vector[1] * np.sin(angle),
|
(
|
||||||
vector[0] * np.sin(angle) + vector[1] * np.cos(angle),
|
vector[0] * np.cos(angle) - vector[1] * np.sin(angle),
|
||||||
))
|
vector[0] * np.sin(angle) + vector[1] * np.cos(angle),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def norm(vector: np.array) -> np.array:
|
def norm(vector: np.array) -> np.array:
|
||||||
|
@ -44,7 +46,7 @@ class Line:
|
||||||
# util.error("cannot create line by one point")
|
# util.error("cannot create line by one point")
|
||||||
self.a: float = start[1] - end[1]
|
self.a: float = start[1] - end[1]
|
||||||
self.b: float = end[0] - start[0]
|
self.b: float = end[0] - start[0]
|
||||||
self.c: float = start.x * end.y - end.x * start.y
|
self.c: float = start[0] * end[1] - end[0] * start[1]
|
||||||
|
|
||||||
def parallel_shift(self, shift: np.array):
|
def parallel_shift(self, shift: np.array):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue