Skip to content

Instantly share code, notes, and snippets.

@serguei-k
Created May 4, 2018 08:06
Show Gist options
  • Save serguei-k/99d94090f55b22db65c7d6e0b6f78d2c to your computer and use it in GitHub Desktop.
Save serguei-k/99d94090f55b22db65c7d6e0b6f78d2c to your computer and use it in GitHub Desktop.
Spherical Coordinates Tutorial Expression 2
float $rate = 3.14 / 2.0;
float $theta = offset.translateX * $rate + control.translateX * $rate;
float $phi = offset.translateY * $rate - control.translateY * $rate;
float $x = sin($theta) * sin($phi);
float $y = cos($phi);
float $z = cos($theta) * sin($phi);
float $px = $x / (1 - $z);
float $py = $y / (1 - $z);
$px = $px * 0.5;
$py = $py * 0.5;
$x = (2 * $px) / (1 + pow($px, 2) + pow($py, 2));
$y = (2 * $py) / (1 + pow($px, 2) + pow($py, 2));
$z = (-1 + pow($px, 2) + pow($py, 2)) / (1 + pow($px, 2) + pow($py, 2));
constraint.translateZ = $z;
constraint.translateX = $x;
constraint.translateY = $y;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment