Jump to content

Accessing a point's coordinate in a local coordinate system (Scripting)


---
 Share

Recommended Posts

Hello,

Is there a way to access the coordinate of a point in any local coordinate system in python scripting?

For example, in GOM Inspect 2022, you can set a local coordinate system as a "Viewing coordinate system" and the "Geometry" label of the point will display the coordinates in the viewing coordinate system. Of course the coordinate could be computed by the python program, but I am just wondering if there is a way of doing this natively in the GOM script api.

Regards,

Alec

Link to comment
Share on other sites

  • 3 months later...

There's nothing built in direct, you can pull them out of the Labels as you describe or compute them, for anyone else with this issue here's a snippet

 

import numpy as np


##csv as gom csv element
target_cs = gom.app.project.inspection['Target CS']

##point as (gom)  3d vec
pt = gom.app.project.inspection['Point 1'].center_coordinate




def vec3d_to_np(v):
	return np.array([v.x, v.y, v.z], dtype=float)



# Origin and axes
O = vec3d_to_np(target_cs.center_coordinate)
X = vec3d_to_np(target_cs.csys_geometry.x_axis)
Y = vec3d_to_np(target_cs.csys_geometry.y_axis)
Z = vec3d_to_np(target_cs.csys_geometry.z_axis)

# Normalize axes
X /= np.linalg.norm(X)
Y /= np.linalg.norm(Y)
Z /= np.linalg.norm(Z)

# Point in global CS
P = vec3d_to_np(pt)

# Vector from CS origin to point
v = P - O

# Project into CS
local_coords = np.array([
	np.dot(v, X),
	np.dot(v, Y),
	np.dot(v, Z)
])

print("Coordinates in target CS:", local_coords)

 

Edited
Link to comment
Share on other sites

 Share

×
×
  • Create New...