private static function createTransform($topLeft, $topRight, $bottomLeft, $alignmentPattern, $dimension)
 {
     $dimMinusThree = (double) $dimension - 3.5;
     $bottomRightX = 0.0;
     $bottomRightY = 0.0;
     $sourceBottomRightX = 0.0;
     $sourceBottomRightY = 0.0;
     if ($alignmentPattern != null) {
         $bottomRightX = $alignmentPattern->getX();
         $bottomRightY = $alignmentPattern->getY();
         $sourceBottomRightX = $dimMinusThree - 3.0;
         $sourceBottomRightY = $sourceBottomRightX;
     } else {
         // Don't have an alignment pattern, just make up the bottom-right point
         $bottomRightX = $topRight->getX() - $topLeft->getX() + $bottomLeft->getX();
         $bottomRightY = $topRight->getY() - $topLeft->getY() + $bottomLeft->getY();
         $sourceBottomRightX = $dimMinusThree;
         $sourceBottomRightY = $dimMinusThree;
     }
     return PerspectiveTransform::quadrilateralToQuadrilateral(3.5, 3.5, $dimMinusThree, 3.5, $sourceBottomRightX, $sourceBottomRightY, 3.5, $dimMinusThree, $topLeft->getX(), $topLeft->getY(), $topRight->getX(), $topRight->getY(), $bottomRightX, $bottomRightY, $bottomLeft->getX(), $bottomLeft->getY());
 }
 public function sampleGrid($image, $dimensionX, $dimensionY, $p1ToX, $p1ToY, $p2ToX, $p2ToY, $p3ToX, $p3ToY, $p4ToX, $p4ToY, $p1FromX, $p1FromY, $p2FromX, $p2FromY, $p3FromX, $p3FromY, $p4FromX, $p4FromY)
 {
     $transform = PerspectiveTransform::quadrilateralToQuadrilateral($p1ToX, $p1ToY, $p2ToX, $p2ToY, $p3ToX, $p3ToY, $p4ToX, $p4ToY, $p1FromX, $p1FromY, $p2FromX, $p2FromY, $p3FromX, $p3FromY, $p4FromX, $p4FromY);
     return $this->sampleGrid_($image, $dimensionX, $dimensionY, $transform);
 }