The obj file loads the coordinates correctly

dujunting80 注册会员
2023-02-27 23:21

This answer quotes ChatGPT

The coordinate offset in the

exported OBJ format file may be due to the difference in the coordinate system. The coordinate system in OBJ format is right-handed, whereas the exported file of DJI may use a left-handed coordinate system. If this is the case, you need to transform the coordinates of the vertices in the OBJ file that you read, from the left hand to the right hand, in order to get the correct coordinates.

Using Python to read an OBJ file, you can use the following code to read the vertex coordinates in the OBJ file:

import numpy as np

vertices = []
with open("Block.obj", "r") as f:
    for line in f:
        if line.startswith("v "):
            parts = line.strip().split(" ")
            vertex = [float(parts[1]), float(parts[2]), float(parts[3])]

vertices = np.array(vertices)

The code above parses the lines starting with "v "in the OBJ file into vertex coordinates, storing them in a NumPy array. However, this does not solve the problem of offset coordinates. To solve the offset problem, you need to convert the left - handed coordinate system to the right - handed coordinate system. This can be done by inverting the Z-axis, as follows:

vertices[:, 2] = -vertices[:, 2]

After inverting the Z-axis, the vertex coordinates are converted from the left - handed coordinate system to the right - handed coordinate system, which can be used for subsequent operations.

About the Author

Question Info

Publish Time
2023-02-27 23:20
Update Time
2023-02-27 23:20