1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """Functions relating to line geometry."""
24
25
26 from numpy import dot
27 from numpy.linalg import norm
28
29
31 """Determine the closest position on the line to the given point.
32
33 This function defines the line using any two points on the line.
34
35
36 @keyword line_pt1: The first point defining the line.
37 @type line_pt1: numpy rank-1 array
38 @keyword line_pt2: The second point defining the line.
39 @type line_pt2: numpy rank-1 array
40 @keyword point: The point.
41 @type point: numpy rank-1 array
42 @return: The position on the line closest to the point.
43 @rtype: numpy rank-1 array
44 """
45
46
47 vect = line_pt2 - line_pt1
48
49
50 return closest_point_ax(line_pt=line_pt1, axis=vect, point=point)
51
52
54 """Determine the closest position on the line to the given point.
55
56 This function defines the line using any point on the line and the axis.
57
58
59 @keyword line_pt1: The point defining the line.
60 @type line_pt1: numpy rank-1 array
61 @keyword axis: The axis defining the line.
62 @type axis: numpy rank-1 array
63 @keyword point: The point.
64 @type point: numpy rank-1 array
65 @return: The position on the line closest to the point.
66 @rtype: numpy rank-1 array
67 """
68
69
70 hypo = point - line_pt
71 hypo_len = norm(hypo)
72 unit_hypo = hypo / hypo_len
73
74
75 axis = axis / norm(axis)
76
77
78 d = hypo_len * dot(axis, unit_hypo)
79
80
81 return line_pt + d*axis
82