Let the coordinates of A be (0, 0) and B (0, 633). C is 257 someunits (let's say meters, we don't care) from A and 390 m from B.
Distance A-C: sqrt (x² + y²) = 257 <=> x² + y² = 257² (1)
Distance B-C: sqrt (x² + (633 - y)²) = 390 <=> x² + (633 - y)² = 390² (2)
Substrating 2 from 1: y² - (633 - y)² = 257² - 390²
<=> (y + a - y)(y - a + y) = 257² - 390²
<=> a (2 y - a) = 257² - 390²
<=> y = (257² - 390²) / 2a + a/2
Similarly:
x² + y² = 257²
<=> x = +/- sqrt ( 257² - y²)
####
use strict;
use warnings;
my %coordinates;
$coordinates{A} = [0,0];
$coordinates{B} = [0,633];
$coordinates{C} = find_coord(257, 390, undef);
$coordinates{D} = find_coord(91, 661, 228);
print "@{$coordinates{D}} \n";
sub find_coord {
my ($a, $b, $c) = @_;
my $sq_dist_dif = $a*$a - $b*$b;
my $y = $sq_dist_dif/(633*2) + 633/2;
my $x = sqrt ($a*$a - $y*$y);
return [$x, $y] unless defined $c;
my $dist_2_c_1 = distance ([$x, $y], $coordinates{C}, $c);
my $dist_2_c_2 = distance ([-$x, $y], $coordinates{C}, $c);
$dist_2_c_1 < $dist_2_c_2 ? [$x, $y, $dist_2_c_1] : [-$x, $y, $dist_2_c_2];
}
sub distance {
return abs (sqrt (($_[0][0] - $_[1][0])**2 + ($_[0][1] - $_[1][1])**2) - $_[2]);
}
####
use strict;
use warnings;
use Data::Dumper;
my %coordinates;
$coordinates{A} = [0,0];
$coordinates{B} = [0,90];
while () {
my ($site, $dA, $dB, $dC) = /(\w):\s+(\d+)\s+(\d+)\s+(\d+)/;
$coordinates{$site} = find_coord ($dA, $dB, $dC);
}
print Dumper \%coordinates;
sub find_coord {
my ($a, $b, $c) = @_;
my $sq_dist_dif = $a*$a - $b*$b;
my $y = $sq_dist_dif/(90*2) + 90/2;
my $x = sqrt ($a*$a - $y*$y);
return [$x, $y] unless $c;
my $dist_2_c_1 = distance ([$x, $y], $coordinates{C}, $c);
my $dist_2_c_2 = distance ([-$x, $y], $coordinates{C}, $c);
$dist_2_c_1 < $dist_2_c_2 ? [$x, $y, $dist_2_c_1] : [-$x, $y, $dist_2_c_2];
}
sub distance {
return abs (sqrt (($_[0][0] - $_[1][0])**2 + ($_[0][1] - $_[1][1])**2) - $_[2]);
}
__DATA__
C: 64 76 0
D: 28 70 74
E: 120 62 68
F: 68 52 93
G: 53 125 64
####
$ perl coordinates2.pl
$VAR1 = {
'F' => [
'-39.0540935398867',
'55.6666666666667',
'1.33876031467558'
],
'A' => [
0,
0
],
'D' => [
'-17.1497975368678',
'22.1333333333333',
'2.41895858461325'
],
'C' => [
'53.1402755816047',
'35.6666666666667'
],
'G' => [
'46.0712491690859',
'-26.2',
'1.73078144969754'
],
'E' => [
'60.4799895486306',
'103.644444444444',
'0.372872345124534'
],
'B' => [
0,
90
]
};
####
A 0 0
B O 90
C 55 35
D -20 20
E 60 114
F 64 55
G 45 -29