How to get the position relative to the other component

now i want to get the position relative to the other component, then move one composition to some place, in then end, according the relative position, move the other composition to the other place.

who can help me?

but my method are below, but it failed

relative_postion = one_component.transformation.origin - other_component.transformation.other.

# move one_component to the origin(500, 500, 500)
one_component_vector = Geom::Point3d(0, 0, 0).vector_to(500, 500, 500)
one_component_transformation = Geom::Transformation::translation(one_component_vector)
one_component.transform!(one_component_transformation)

other_component_vector = Geom::Point3d(500, 500, 500).vector_to(relative_postion)
other_component_transformation = Geom::Transformation::translation(other_component_vector)
other_component.transform!(other_component_transformation)

but the other component’s relative position changed. it’s not my unexpected result.

You must use class constructor calls:

one_component_vector = Geom::Point3d::new(0, 0, 0).vector_to(Geom::Point3d::new(500, 500, 500))

But this is a bit easier:

one_component_vector = Geom::Vector3d::new(500, 500, 500)
one_component_transformation = Geom::Transformation::translation(one_component_vector)
one_component.transform!(one_component_transformation)

And this is easiest:

one_component.transform!( [500, 500, 500] )

… because SketchUp Ruby Array class is compatible with Vectors and Points.

Here is another way:

third_component.transform!( 
    one_component.transformation.origin +
    other_component.transformation.origin
)

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.