How does the true north of the wgs84 coordinate system point towards the z-axis

I used the wgs84 coordinate array to convert to the coordinates of babylonjs, and then generated a road. I need to point the positive z-axis of babylonjs to the north of the map, but I found that the road I generated has some deviation from the angle on the map. Can you help me find the problem? How can I make the positive z-axis of babylonjs point to the north of the map? How many degrees do I need to rotate it?

The bridges in the two images above are not aligned. The first image is a map, and the second image is the road surface generated by me according to the wgs84 coordinate array

export const latLngToXyz = (latLng: LatLng, height = 0) => {
  const [lat, lng] = latLng
  const latitude_rad = lat * Math.PI / 180
  const longitude_rad = lng * Math.PI / 180
  const earthRadiusA = 6378137
  const earthRadiusB = 6356752.31424518
  const e = (Math.pow(earthRadiusA, 2) - Math.pow(earthRadiusB, 2)) / Math.pow(earthRadiusA, 2)

  const n = earthRadiusA / Math.sqrt(1 - e * Math.pow(Math.sin(latitude_rad), 2))
  const nh = n + height
  const xPos = nh * Math.cos(latitude_rad) * Math.cos(longitude_rad)
  const zPos = nh * Math.cos(latitude_rad) * Math.sin(longitude_rad)
  const yPos = Math.sin(latitude_rad) * ( Math.pow(earthRadiusB, 2 * n / Math.pow(earthRadiusA, 2)))
  return new BABYLON.Vector3(xPos, yPos, zPos)
}

This is my method of converting wgs84 coordinates to xyz coordinates. It seems that the generated coordinates are not very accurate. Is there a reliable method to capture Huawei’s xyz coordinates from wgs84 coordinates

I asked CoPilot your question. I hope there are some good ideas for solve your problem:

In Babylon.js, ensuring that the positive Z-axis aligns with the north direction on your map involves a few considerations. Let’s break it down:

  1. Coordinate System Orientation:
  • By default, Babylon.js uses a left-handed coordinate system with the Y-axis pointing up. This means that the positive Z-axis points forward.
  • However, you’re working with data that follows a right-handed Z-up coordinate system (commonly used in geospatial applications).
  • To achieve alignment, you’ll need to adjust your Babylon.js scene accordingly.
  1. Camera Position and Target:
  • When using the right-handed Z-up system, ensure that your camera’s position and target are provided in Y-up coordinates.
  • Set the camera’s upVector to (0, 0, 1) to maintain the correct orientation.
  1. Mesh Position Coordinates:
  • Babylon.js handles mesh position coordinates in Z-up even when using the right-handed system.
  • So, when creating your road, make sure the mesh positions are specified in Z-up coordinates.
  1. Consistency and Transformations:
  • Consistency is key. If your data is in Z-up, consider transforming all input and output vectors and models into the correct coordinate system.
  • Alternatively, you can use scene.useRightHandedSystem, but remember that Babylon.js still operates in a Y-up system (with right-handed mode).
  1. Mesh Rotation:
  • To rotate your road to align with the north direction, you can use Mesh.lookAt(clickPoint) where clickPoint represents the north direction.
  • This function will adjust your model’s rotation on all three axes to face the specified point.
  1. Degrees of Rotation:
  • The exact number of degrees you need to rotate depends on your specific use case and the deviation you’ve observed.
  • Experiment with different angles until your road aligns correctly with the map.

Remember that Babylon.js primarily operates in a left-handed Y-up system, so you might encounter some inconsistencies when working with a right-handed Z-up system.
If possible, consider exporting or re-exporting your scene in a Y-up orientation to avoid constant adjustments12.

Weitere Informationen

1forum.babylonjs.com

2forum.babylonjs.com

3endoc.cnbabylon.com

1 Like

Your current method for converting WGS84 coordinates to XYZ coordinates is a good start, but it’s essential to consider the intricacies of geodetic transformations. Let’s explore some improvements and alternatives:

  1. Geodetic to Geocentric Conversion:
  • Your existing method calculates XYZ coordinates based on the WGS84 ellipsoid. However, for precise geospatial applications, you might want to use established libraries or tools.
  • Consider using the pyproj library (Python) or similar tools that provide accurate geodetic-to-geocentric conversions.
  • Pyproj allows you to transform between different coordinate systems, including WGS84 and local Cartesian.
  1. Similitude Transformation:
  • To achieve better accuracy, you can perform a similitude transformation from your local Cartesian system to the geocentric system.
  • The similitude transformation involves finding the parameters (scale, rotation, translation) that align your local coordinates with the global WGS84 system.
  • I recommend referring to the math paper by Huaien Zeng et al. (2018) for details on this transformation1.
  1. Using Pyproj and Simil Module:
  1. Sample Code:
  • Here’s an example of how you can use the pyproj library and the simil module to convert your local Cartesian points to WGS84 coordinates:

Python

from pyproj import CRS, Transformer
import numpy as np
import simil

# Local Cartesian [x, y, z] control points
local_ctrl_p = [[0, 0, 0], [0, 12.24, 0], [32.42, 6.79, 0]]

# Geodetic [lat, lon, h] control points
geodet_ctrl_p = [
    [43.88072176381581, 11.072238294111774, 53],
    [43.88099406334439, 11.072485923398222, 53],
    [43.88080644977896, 11.072808964924704, 53]
]

# Perform similitude transformation
simil_params = simil.find_similitude(local_ctrl_p, geodet_ctrl_p)
transformer = Transformer.from_crs("EPSG:4326", "EPSG:4978")  # WGS84 to geocentric

# Convert other points (local Cartesian) to geocentric
other_points_local = [...]  # Add your other local points here
other_points_geocentric = [simil.apply_similitude(p, simil_params) for p in other_points_local]

# Convert geocentric points to geodetic (WGS84)
other_points_geodetic = [transformer.transform(p[0], p[1], p[2]) for p in other_points_geocentric]

# Now you have the WGS84 coordinates for your other points
print(other_points_geodetic)

KI-generierter Code. Überprüfen und sorgfältig verwenden. Weitere Informationen zu häufig gestellten Fragen.

Remember to adjust the code according to your specific dataset and requirements. The similitude transformation should help improve the accuracy of your conversions from local Cartesian to WGS84 coordinates1.

Keep in mind that geodetic transformations involve complex mathematical models, and using established libraries ensures better accuracy and consistency.

Weitere Informationen

1gis.stackexchange.com2gis.stackexchange.com3gis.stackexchange.com4coordinates-converter.com5github.com+3 mehr

Copilot: Copilot mit GPT-4 (bing.com)

3 Likes

Thank you for your answer. After carefully studying your answer, I finally found the problem. The reason why the bridges in the map are not aligned is because the map uses the coordinate system of Web Mercator, which looks different. Therefore, I used your suggestion to find an NPM class library“ Home | math.gl “,” math.gl - npm search It solved my problem. After converting the wgs84 coordinate system to Mercator plane coordinates, the bridge in the figure was aligned. Thank you very much for your answer, which pointed me in the direction

2 Likes