function projectile_distance ($inital_velocity, $angle, $initial_height, $g
{
$angle = deg2rad$angle);
$distance = ($inital_velocitycos$angle)/$g
* ($inital_velocitysin$angle)
+ sqrtpow$inital_velocitysin$angle),2)+2*$g$initial_height));
return $distance
}
Author: ToneDJCampbell
eXorithm – Execute Algorithm: Embed Algorithm simple_sort
Embed This Algorithm
This page will help you embed the algorithm simple_sort on a page on your own website. Just configure the inputs, then click the generate button to get a snippet of code you can paste onto your site. You have two options.
- You can embed the entire form. Users will be able to enter their own arguments, and will need to press the run button to execute the algorithm.
- You can add only the output of the algorithm to your website. There will be no argument inputs or run button.
eXorithm – Execute Algorithm: View / Run Algorithm set_unix_time
function set_unix_time ($year$month$day$hour$minute$second
{
return mktime$hour$minute$second$month$day$year);
}
eXorithm – Execute Algorithm: Algorithms Beginning with V
eXorithm – Execute Algorithm: View / Run Algorithm hailstone
function hailstone ($number
{
$result = array();
while ($number > 1) {
$result[] = $number
if ($number & 1)
$number = 3 * $number + 1;
else
$number = $number / 2;
}
$result[] = $number
return $result
}
eXorithm – Execute Algorithm: History For Algorithm round_corners
round_corners    version 0.2    Round the corners of an image. Transparency and anti-aliasing are supported.
eXorithm – Execute Algorithm: View / Run Algorithm blur_image
function blur_image ($image, $level
{
// based on http://www.tuxradar.com/practicalphp/11/2/25
$imagex = imagesx$image);
$imagey = imagesy$image);
$tc = imageistruecolor$image);
$new_image = imagecreatetruecolor$imagex, $imagey);
imagealphablending$new_image, false);
imagesavealpha$new_image, true);
$level = $level-1;
for ($x = 0; $x < $imagex; ++$x) {
for ($y = 0; $y < $imagey; ++$y) {
$newr = 0;
$newg = 0;
$newb = 0;
$newt = 0;
$colours = array();
$thiscol = imagecolorat$image, $x, $y);
for ($k = $x - $level; $k <= $x + $level; ++$k) {
for ($l = $y - $level; $l <= $y + $level; ++$l) {
if ($k < 0) { $colours[] = $thiscol; continue; }
if ($k >= $imagex) { $colours[] = $thiscol; continue; }
if ($l < 0) { $colours[] = $thiscol; continue; }
if ($l >= $imagey) { $colours[] = $thiscol; continue; }
$colours[] = imagecolorat$image, $k, $l);
}
}
foreach$colours as $colour) {
if ($tc) {
$newr += ($colour >> 16) & 0xFF;
$newg += ($colour >> 8) & 0xFF;
$newb += $colour & 0xFF;
$newt += ($colour >> 24) & 0xFF;
} else {
$c = imagecolorsforindex$image, $colour);
$newr += $c'red'];
$newg += $c'green'];
$newb += $c'blue'];
$newt += $c'alpha'];
}
}
$numelements = count$colours);
$newr /= $numelements
$newg /= $numelements
$newb /= $numelements
$newt /= $numelements
$newcol = imagecolorallocatealpha$new_image, $newr, $newg, $newb, $newt);
imagesetpixel$new_image, $x, $y, $newcol);
}
}
return $new_image
}
eXorithm – Execute Algorithm: View / Run Algorithm triangulate
function triangulate ($side1, $side2, $side3, $angle1, $angle2, $angle3, $radians
{
  $sides = array();
  $angles = array();
 Â
  // get sides
  if ($side1!='') $sides[1] = $side1+0;
  if ($side2!='') $sides[2] = $side2+0;
  if ($side3!='') $sides[3] = $side3+0;
 Â
  // get angles
  if ($angle1!='') $angles[1] = $angle1+0;
  if ($angle2!='') $angles[2] = $angle2+0;
  if ($angle3!='') $angles[3] = $angle3+0;
 Â
  // convert to radians if necessary
  if (!$radians) {
    foreach ($angles as $angle => $value) {
      $angles$angle] = deg2rad$value);
    }
  }
 Â
  // need 3 values and at least one side
  if (((count$sides)+count$angles))!=3) || (count$sides)==0)) {
    throw new Exception"You must only provide 3 values for the sides and angles. At least one value must be a side. Leave the other three values blank.");
  }
 Â
  // iterate three times to make sure that we get everything
  for ($count=0;$count<3;$count++) {
    // for the three sides/angles
    for ($i1=1;$i1<=3;$i1++) {
      $i2 = ($i1 % 3)+1; // the other side/angle
      $i3 = (($i1+1) % 3)+1; // the other other side/angle
      if (!isset$angles$i1])) {
        // try $angle1 = 180 - $angle2 - $angle3
        if ((isset$angles$i2])) && (isset$angles$i3]))) {
          $angles$i1] = pi() - $angles$i2] - $angles$i3];
        }
      }
      if (!isset$sides$i1])) {
        if (isset$angles$i1])) {
          // try $side1 = $side2 * (sin($angle1)/sin($angle2))
          if ((isset$sides$i2])) && (isset$angles$i2]))) {
            $sides$i1] = $sides$i2] * sin$angles$i1]) / sin$angles$i2]);
          }
          // try $side1 = $side3 * (sin($angle1)/sin($angle3))
          if ((isset$sides$i3])) && (isset$angles$i3]))) {
            $sides$i1] = $sides$i3] * sin$angles$i1]) / sin$angles$i3]);
          }
        }
      }
      if (!isset$angles$i1])) {
        if (isset$sides$i1])) {
          // try $angle1 = arcsin(sin($angle2) * $side1/$side2)
          if ((isset$sides$i2])) && (isset$angles$i2]))) {
            $angles$i1] = asinsin$angles$i2]) * $sides$i1] / $sides$i2]);
          }
          // try $angle1 = arcsin(sin($angle3) * $side1/$side3)
          if ((isset$sides$i3])) && (isset$angles$i3]))) {
            $angles$i1] = asinsin$angles$i3]) * $sides$i1] / $sides$i3]);
          }
        }
      }
      if (!isset$sides$i1])) {
        // try $side1 = sqrt($side2^2 + $side3^2 - 2*$side2*$side3*cos($angle1))
        if ((isset$sides$i2])) && (isset$sides$i3])) && (isset$angles$i1]))) {
          $sides$i1] = sqrt$sides$i2]*$sides$i2] + $sides$i3]*$sides$i3] - 2 * $sides$i2] * $sides$i3] * cos$angles$i1]));
        }
      }
      if (!isset$angles$i1])) {
        // try $angle1 = arccos($side2^2 + $side3^2 - $side1^2 / 2*$side2*$side3))
        if ((isset$sides$i2])) && (isset$sides$i3])) && (isset$sides$i1]))) {
          $angles$i1] = acos(($sides$i2]*$sides$i2] + $sides$i3]*$sides$i3] - $sides$i1]*$sides$i1]) / (2 * $sides$i2] * $sides$i3]));
        }
      }
    }
    // were we able to calculate everything?
    if ((count$sides)+count$angles))==6) break
  }
 Â
  // bad values?
  foreach ($angles as $value) {
    if (is_nan$value) || is_infinite$value) || ($value<=0)) {
      throw new Exception"A triangle cannot be constructed with those values.");
    }
  }
 Â
  ksort$sides);ksort$angles);
 Â
  // convert to degrees if necessary
  if (!$radians) {
    foreach ($angles as $angle => $value) {
      $angles$angle] = rad2deg$value);
    }
  }
 Â
  return (array'sides'=>$sides, 'angles'=>$angles));
}Â
eXorithm – Execute Algorithm: View / Run Algorithm backwards
function backwards ($text
{
// this function will put the words in $text backwards
$text = str_replace" ", " ", $text);
$text = strip_tags$text);
$text = str_replace"n", " ", $text);
$text = str_replace"r", " ", $text);
$text = preg_replace'/s+/', ' ', $text);
$arr = explode" ", $text);
$arr = array_reverse$arr);
return implode" ", $arr);
}
Magic8Ball
<?php /** * magic8ball * * Ask the magic 8 ball your question. * * @version 0.2 * @author Contributors at eXorithm * @link /algorithm/view/magic8ball Listing at eXorithm * @link /algorithm/history/magic8ball History at eXorithm * @license /home/show/license * * @return mixed */ function magic8ball() { $answers =array('It is certain', 'It is decidedly so', 'Without a doubt', 'Yes โ definitely', 'You may rely on it', 'As I see it, yes', 'Most likely', 'Outlook good', 'Signs point to yes', 'Yes', 'Reply hazy, try again', 'Ask again later', 'Better not tell you now', 'Cannot predict now', 'Concentrate and ask again', 'Don\'t bet on it', 'My reply is no', 'My sources say no', 'Outlook not so good', 'Very doubtful' ); $index = rand(0, count($answers)); return ($answers[$index]); } ?>