DIsplacement of shapes while doing transform

edited January 2015
Hi,

I want to rotate all the shapes on a given layer by some angle lets say 45 degrees.
But while applying transform on shapes particularly on box, they get shifted too much. I want to have rotation such that after rotation centers should not get displaced too much. I am using following script, could you please tell me if i am doing something wrong

##layers is a file with format <layer_no> <datatype> <angle of rotation>
if \$layers
layers_info = File.open(\$layers)
layers_info.each do |linfo|
linfo_arr = linfo.split(/\s/).map(&:to_i)
if linfo_arr.length != 3
puts "\$layers format should <layer_number> <datatype> <angle>"
exit
else
angle=linfo_arr[2]
layer_index = lay.layer(linfo_arr[0],linfo_arr[1])
lay.each_cell_top_down do |cell|
#puts(lay.cell_name(cell))
cell_ptr = lay.cell(cell)
cell_ptr.shapes(layer_index).each do |shape|
if shape.is_polygon? || shape.is_box?
#if shape.is_box?
#bcen=shape.box_center()
#puts(bcen)
rot=RBA::ICplxTrans::new(1,angle,false,RBA::Point::new)
cell_ptr.shapes(layer_index).transform(shape,rot)
#shape.box_center(bcen)
end
end
end
end
end
end

Regards,
Heena

• edited January 2015

Hi Heena,

Transformation happens in the coordinate system of the cell. So rotations are applied using the origin of the cell as the center of rotation.

To rotate around the center of the shape, you can first transform the shape so the center is at the origin, then apply the rotation and the transform it back. These three steps can be combined into a single transformation, i.e.

``````bcen = shape.bbox.center
rot_centered = RBA::ICplxTrans::new(1,0,false,bcen) *
RBA::ICplxTrans::new(1,angle,false,RBA::Point::new) *
RBA::ICplxTrans::new(1,0,false,-bcen)
shape.transform(rot_centered)
``````

Matthias

• edited 11:40AM
Hi Matthias,

Thanks a lot.

I'll try this solution.

Regards,
Heena