def testLLFToECEF(self): (lon, lat, alt) = (0, 0, 0) (x, y, z) = LLH2ECEF(lon, lat, alt) self.assertEqual(x, 6378137.0) self.assertEqual(y, 0.0) self.assertEqual(z, 0.0) # Swiss like lon/lat/alt (Bern) (lon, lat, alt) = (7.43861, 46.951103, 552) (x, y, z) = LLH2ECEF(lon, lat, alt) self.assertEqual(round(x, 2), 4325328.22) self.assertEqual(round(y, 2), 564726.19) self.assertEqual(round(z, 2), 4638459.21) # Swiss like lon/lat/alt (Raron) (lon, lat, alt) = (7.81512, 46.30447, 635.0) (x, y, z) = LLH2ECEF(lon, lat, alt) self.assertEqual(round(x, 2), 4373351.17) self.assertEqual(round(y, 2), 600250.39) self.assertEqual(round(z, 2), 4589151.29) # Swiss like lon/lat/alt (near Raron) (lon, lat, alt) = (7.81471, 46.306686, 635.0) (x, y, z) = LLH2ECEF(lon, lat, alt) self.assertEqual(round(x, 2), 4373179.0) self.assertEqual(round(y, 2), 600194.88) self.assertEqual(round(z, 2), 4589321.47)
def calculate_weighted_normals_for(self, triangles): """ Calculates normal vectors for the specified triangles, this normal vectors are not normalized and multiplicated with the area of participating triangle :rtype: Array :param triangles: :return: Array of not normalized vectors [float,float,float] """ weighted_normals = [] for triangle in triangles: llh0 = self._uvh_to_llh(triangle[0]) llh1 = self._uvh_to_llh(triangle[1]) llh2 = self._uvh_to_llh(triangle[2]) v0 = LLH2ECEF(llh0[0], llh0[1], llh0[2]) v1 = LLH2ECEF(llh1[0], llh1[1], llh1[2]) v2 = LLH2ECEF(llh2[0], llh2[1], llh2[2]) normal = np.cross(c3d.subtract(v1, v0), c3d.subtract(v2, v0)) area = triangleArea(v0, v1) weighted_normals.append(normal * area) return weighted_normals
def testBoundingSpherePrecision(self): x = 533 y = 383 z = 9 geodetic = GlobalGeodetic(True) [minx, miny, maxx, maxy] = geodetic.TileBounds(x, y, z) ter = TerrainTile(west=minx, south=miny, east=maxx, north=maxy) ter.fromFile('tests/data/%s_%s_%s.terrain' % (z, x, y)) coords = [LLH2ECEF(*coord) for coord in ter.getVerticesCoordinates()] sphere = BoundingSphere() sphere.fromPoints(coords) for coord in coords: distance = c3d.distance(sphere.center, coord) self.assertLessEqual(distance, sphere.radius)
def llh2ecef(x): return LLH2ECEF(x[0], x[1], x[2])