Here's what I am planning to use.. This is to get the coordinates of the corners of the cropping box..
#!/usr/bin/perl -w
use strict;
use Math::Complex;
# box1 is the image
my @box1 = (-150,-150,150,-150,150,150,-150,150);
#box 2 is the cropping box
my @box2 = (-300,-75,0,-75,0,75,-300,75);
my @box2r = save_rotate_points(undef,45,@box2);
print "Rotate BOX 2\n";
foreach my $x (@box2r) {
print $x , "\n";
}
my ($x1,$y1,$x2,$y2) = get_rotation_box(undef,@box2r);
my @points = ($x1,$y1,$x2,$y1,$x2,$y2,$x1,$y2);
print "Bounding Box:\n";
foreach my $x (@points) {
print $x , "\n";
}
sub save_rotate_points {
my ($widget,$angle,@points) = @_;
my $count = @points;
my (@x, @y);
$angle = $angle * pi() / 180;
for(my $i = 0; $i < $count ; $i+=2){
my $xp = ($points[$i] * cos($angle)) - ($points[$i+1] * sin($a
+ngle));
my $yp = ($points[$i] * sin($angle)) + ($points[$i+1] * cos($a
+ngle));
push @x, $xp;
push @y, $yp;
}
@points = ($x[0],$y[0],$x[1],$y[1],$x[2],$y[2],$x[3],$y[3]);
return @points;
}
sub get_center_rectangle {
my ($widget,@points) = @_;
my $deltax = ($points[0]+$points[2]+$points[4]+$points[6])/4;
my $deltay = ($points[1]+$points[3]+$points[5]+$points[7])/4;
return $deltax,$deltay;
}
sub get_rotation_box {
my ($widget,@points) = @_;
# get smallest value
my $i = 0;
my ($smallx,$smally,$bigx,$bigy) = (0,0,0,0);
foreach my $x (@points) {
if($i == 0){
if($x <= $smallx){
$smallx = $x;
}
if($x >= $bigx){
$bigx = $x;
}
}else{
if($x <= $smally){
$smally = $x;
}
if($x >= $bigy){
$bigy = $x;
}
$i = -1;
}
$i++;
}
return $smallx,$smally,$bigx,$bigy;
}
sub move_points {
my ($widget,$mx,$my,@points) = @_;
my $i = 0;
my @new_points;
print $mx," ",$my,"\n";
foreach my $x (@points) {
if($i == 0){
print $x , "+" , $mx , "\n";
$x+=$mx;
}else{
$x+=$my;
$i = -1;
}
push @new_points, $x;
$i++;
}
return @new_points;
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.