# Calculating distance relative to current active group/component axes

Hello, this is my first time posting a question. Hopefully i do not violate any forum rules

I am trying to achieve this, as picture shows.
Let’s say that I am inside a group when I want to operate this.
Calculating distance of a point / vertices of an edge to current active group.
What i am doing is the A distance as picture shows.
Here is my current code

sketch = Sketchup.active_model
selection = sketch.selection
pointToCalculate = selection[0].start
resultX = pointToCalculate.position.x

#or in short
resultX = Sketchup.active_model.selection[0].start.position.x

#what i am trying to achieve
goalX = resultX - currentOriginRelativeToAxes
#currentOriginRelativeToAxes = ??

To get the calculation to perform in relative axes / relative origin.
I’ve been looking at the API but found no clue how to get the calculation.

#this also doesn't help
goalX = Sketchup.active_model.axes.origin - resultX
#giving C distance

Is there anyway to calculate the distance relative to group axes?
The goal is to get B distance
Thank you.

The origin of your component in the components’ coordinate system is [0,0,0].
To get that same point in global coordinates, you need to use the transformation of the component:

origin_in_local_coordinates = Geom::Point3d.new(0,0,0)
origin_in_global_coordinates = origin_in_local_coordinates.transform(my_component_instance.transformation)
1 Like

Another way to get the global coordinates, especially if your instance is nested, is to use the InstancePath class.

model = Sketchup.active_model
nesting = model.active_path
nesting.push(selection[0])
ip = Sketchup::InstancePath.new(nesting)
t = ip.transformation
sel_origin = ORIGIN.transform(t)

REF: