Dan, Thank you for your reply.
Origin of the group g.transformation.origin
is (150, 10, 3). One of the corners' (say P) coordinate of RectangleBox is (19, 0, 0). (RectangleBox is ComponentInstance and belongs to the group.
Seeing the value (19,0,0) and the position of the point P, it is clear the coordinate is with respect to the Group's coordinate system. So I need to add the group's origin to get the coordinates of P in Sketchup coordinate system. That would be - (169, 10, 3).
Question: This looks like the hard way. Is there any direct way?
Let me give you the actual picture.
Problem I am trying to solve: Find all the faces that are touching (in contact with) other faces in the selection.
The approach
- I get all the plys (RectangleBoxes i.e., ComponentInstances) in the selection (Recursive solution).
- Then I get all the faces of the plys
- I go on to compare each face against every other face to see if they are in contact. If they are then I add it to the resulting array.
**Another query:**In get_extremes_of_face
method face.vertices
returns vertices with respect to the Group's origin. And this is where i will need to offset the origin of the group to get the 'absolute coordinates'. But is there a better way to do this?
def get_all_faces(ply)
entities = ply.definition.entities
all_faces = []
for entity in entities
if entity.instance_of?(Sketchup;;Face)
all_faces << entity
end
end
return all_faces
end
def is_face_coplanar_to_another?(face1, face2)
face1_extremes = get_extremes_of_face(face1)
face2_extremes = get_extremes_of_face(face2)
if(face1.area > face2.area)
val = check_if_one_extremes_contain_another(face1_extremes, face2_extremes)
else
val = check_if_one_extremes_contain_another(face2_extremes, face1_extremes)
end
return val
end
def get_extremes_of_face(face)
vertices = face.vertices
i = 0
array = []
x_value1 = []
y_value1 = []
z_value1 = []
for ii in (0..3)
array[i] = vertices[ii].position
x_value1[i] = array[i][0]
y_value1[i] = array[i][1]
z_value1[i] = array[i][2]
i += 1
end
x_min = x_value1.min
x_max = x_value1.max
y_min = y_value1.min
y_max = y_value1.max
z_min = z_value1.min
z_max = z_value1.max
value = {;x_min => x_min,;x_max => x_max,;y_min => y_min,;y_max => y_max,;z_min => z_min,;z_max => z_max}
return value
end
def check_if_one_extremes_contain_another(ex1, ex2)
if (ex1[;x_min] <= ex2[;x_min] && ex1[;y_min] <= ex2[;y_min] && ex1[;z_min] <= ex2[;z_min])
if(ex2[;x_max] <= ex1[;x_max] && ex2[;y_max] <= ex1[;y_max] && ex2[;z_max] <= ex1[;z_max])
return true
else
return false
end
end
return false
end