the following script might be what you're looking for:
PHP Code:
my $loop = 1;
while (<>)
{
my $delta_x, $x_i, $y_i, $x_k, $y_k;
if ($loop == 1) {
($x_i, $y_i, $x_k, $y_k) = split
}
else {
($x_i, $y_i) = ($x_k, $y_k);
($x_k, $y_k) = split
}
$delta_x = ($x_k - $x_i) / 2;
my $x_j = $x_i + $delta_x;
my $y_j = (($x_j - $x_k) / ($x_i - $x_k)) * $y_i + (($x_j - $x_i) / ($x_k - $x_i)) * $y_k;
print $x_i,"\t",$y_i,"\n(",$x_j,")\t(",$y_j,")\n";
$loop++;
}
when you run the script, the data should be entered as follows:
- first input line: two couples of coordinates (i.e. two points);
- next input lines: a couple of coordinates (i.e. one point).
Bookmarks