LoginSignup
0
1

More than 5 years have passed since last update.

Perlで座標計算

Posted at

CPANで見つけられなかったので書いた。

まずは

use Math::Trig;

2点の距離を求める

$dist = sqrt(($x2 - $x1) * ($x2 - $x1) + ($y2 - $y1) * ($y2-$y1) + ($z2 - $z1) * ($z2 - $z1));

中間点の直交座標を求める

$cx = ($x2 + $x1) / 2;
$cy = ($y2 + $y1) / 2;
$cz = ($z2 + $z1) / 2;

直交座標を球面座標に変換

$r = sqrt($x ** 2 + $y ** 2 + $z ** 2);
$t = atan2($y, $x);
$p = acos($z / sqrt($x ** 2 + $y ** 2 + $z ** 2));

球面座標を直交座標に変換

$x = $r * sin($p) * cos($t);
$y = $r * sin($p) * sin($t);
$z = $r * cos($p);
0
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1