I'm working on a placement tool and trying to determine which corner is which of the bounding box using the cursor... here's the code I came up with to try and do that...
Iterate selection...
@bbox_points_array=[]
@coord=[]
@selection.each{|entity|
if entity.parent==@model
parent=entity
old_comp_origin=parent.transformation.origin
trans=entity.transformation.to_a
vector=Geom;;Vector3d.new(trans[0], trans[4], trans[8])
if trans[1]<0
multiplier=-1
else
multiplier=1
end
old_comp_angle=((X_AXIS.angle_between(vector)).radians)*multiplier
@coord << old_comp_origin << old_comp_angle << parent
parent_bounding_box=parent.bounds
for i in 0..7
point=parent_bounding_box.corner(i)
@bbox_points_array << point.to_a
end
end
... then use I use the cursor input point and compare it to the array I created above to see if there's a match... I round the decimals just to make them more legible...
cursor_input_point=@ip.position.to_a
corner=0
@bb_corner=[]
@main_module.bbox_point3d.each{|bbox_corner|
bbox_input_point_array=[bbox_corner[0].round(6), bbox_corner[1].round(6), bbox_corner[2].round(6)]
cursor_input_point_array=[cursor_input_point[0].round(6), cursor_input_point[1].round(6), cursor_input_point[2].round(6)]
if bbox_input_point_array==cursor_input_point_array
@bb_corner << corner
end
corner+=1
}
This works as long as the component is aligned with one of the axes if it's rotated ie: 45deg, the array point3ds are all off. I suspect this is due to the transformation that is applied to the component but I have no idea how to fix it.
Here's an example of an array with the compoent aligned on the x axis at origin [0, 0, 0]...
[[0.0, 0.0, 0.0], [22.000000000000007, 0.0, 0.0], [0.0, 22.000000000000007, 0.0], [22.000000000000007, 22.000000000000007, 0.0], [0.0, 0.0, 22.0], [22.000000000000007, 0.0, 22.0], [0.0, 22.000000000000007, 22.0], [22.000000000000007, 22.000000000000007, 22.0]]
and the same component rotated 45deg...
[[-15.55634918610406, -5.024295867788081e-15, 0.0], [15.556349186104041, -5.024295867788081e-15, 0.0], [-15.55634918610406, 31.112698372208097, 0.0], [15.556349186104041, 31.112698372208097, 0.0], [-15.55634918610406, -5.024295867788081e-15, 22.0], [15.556349186104041, -5.024295867788081e-15, 22.0], [-15.55634918610406, 31.112698372208097, 22.0], [15.556349186104041, 31.112698372208097, 22.0]]
Any ideas or suggestions?