Rotation calculation

Benchmark created on


Preparation HTML

<script>
  screenW = 320;
  screenH = 480;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Cached calculation
oldCoords = {
 x: Math.floor(Math.random() * (screenW - 90)),
 y: Math.floor(Math.random() * (screenH - 150))
}

newCoords = {
 x: Math.floor(Math.random() * (screenW - 90)),
 y: Math.floor(Math.random() * (screenH - 150))
}

var dx = newCoords.x - oldCoords.x;
var dy = newCoords.y - oldCoords.y;
var rotation2 = Math.atan(dx / dy) * 57.3;
if (dy > 0) {
 rotation2 = 180 - rotation2;
}
if (dy < 0) {
 rotation2 = 0 - rotation2;
}
if (dy == 0) {
 if (dx > 0) {
  rotation2 = 90;
 }
 if (dx < 0) {
  rotation2 = 270;
 }
}
ready
Raw Calculation
oldCoords = {
 x: Math.floor(Math.random() * (screenW - 90)),
 y: Math.floor(Math.random() * (screenH - 150))
}

newCoords = {
 x: Math.floor(Math.random() * (screenW - 90)),
 y: Math.floor(Math.random() * (screenH - 150))
}

var dx = newCoords.x - oldCoords.x;
var dy = newCoords.y - oldCoords.y;
if (dy > 0) {
 var rotation2 = 180 - (Math.atan(dx / dy) * 57.3);
}
if (dy < 0) {
 var rotation2 = 0 - (Math.atan(dx / dy) * 57.3);
}
if (dy == 0) {
 if (dx > 0) {
  var rotation2 = 90;
 }
 if (dx < 0) {
  var rotation2 = 270;
 }
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.