|
1 | 1 | import math |
| 2 | +import numpy as np |
2 | 3 |
|
3 | 4 |
|
4 | 5 | def dms2dd(degrees, minutes, seconds, ms=0): |
@@ -45,6 +46,54 @@ def enh2xyz(e, n, h, eastings, northings, orthogonal_height, x_axis_abscissa, x_ |
45 | 46 | return (x, y, z) |
46 | 47 |
|
47 | 48 |
|
| 49 | +def local2global(matrix, eastings, northings, orthogonal_height, x_axis_abscissa, x_axis_ordinate, scale=None): |
| 50 | + if scale is None: |
| 51 | + scale = 1.0 |
| 52 | + x = np.array([x_axis_abscissa, x_axis_ordinate, 0]) |
| 53 | + x /= np.linalg.norm(x) |
| 54 | + y = np.cross(np.array([0, 0, 1]), x) |
| 55 | + intermediate = ( |
| 56 | + np.matrix( |
| 57 | + [ |
| 58 | + [x[0], y[0], 0, 0], |
| 59 | + [x[1], y[1], 0, 0], |
| 60 | + [x[2], y[2], 1, 0], |
| 61 | + [0, 0, 0, 1], |
| 62 | + ] |
| 63 | + ) |
| 64 | + @ matrix |
| 65 | + ) |
| 66 | + intermediate[0, 3] = (intermediate[0, 3] * scale) + eastings |
| 67 | + intermediate[1, 3] = (intermediate[1, 3] * scale) + northings |
| 68 | + intermediate[2, 3] = (intermediate[2, 3] * scale) + orthogonal_height |
| 69 | + return intermediate |
| 70 | + |
| 71 | + |
| 72 | +def global2local(matrix, eastings, northings, orthogonal_height, x_axis_abscissa, x_axis_ordinate, scale=None): |
| 73 | + if scale is None: |
| 74 | + scale = 1.0 |
| 75 | + x = np.array([x_axis_abscissa, x_axis_ordinate, 0]) |
| 76 | + x /= np.linalg.norm(x) |
| 77 | + y = np.cross(np.array([0, 0, 1]), x) |
| 78 | + result = matrix.copy() |
| 79 | + result[0, 3] = (result[0, 3] - eastings) / scale |
| 80 | + result[1, 3] = (result[1, 3] - northings) / scale |
| 81 | + result[2, 3] = (result[2, 3] - orthogonal_height) / scale |
| 82 | + return ( |
| 83 | + np.linalg.inv( |
| 84 | + np.matrix( |
| 85 | + [ |
| 86 | + [x[0], y[0], 0, 0], |
| 87 | + [x[1], y[1], 0, 0], |
| 88 | + [x[2], y[2], 1, 0], |
| 89 | + [0, 0, 0, 1], |
| 90 | + ] |
| 91 | + ) |
| 92 | + ) |
| 93 | + @ result |
| 94 | + ) |
| 95 | + |
| 96 | + |
48 | 97 | # Used for converting the X and Y vectors of the X Axis in IFC geolocation |
49 | 98 | def xy2angle(x, y): |
50 | 99 | return math.degrees(math.atan2(y, x)) |
0 commit comments