public function getImageCornerLatLngs() { $corners = array(); $rotation = -$this->rotation; $corners["ne"] = new LatLng($this->north, $this->east); $corners["nw"] = new LatLng($this->north, $this->west); $corners["sw"] = new LatLng($this->south, $this->west); $corners["se"] = new LatLng($this->south, $this->east); $projectionOrigin = new LatLng(($this->north + $this->south) / 2, ($this->east + $this->west) / 2); $projectedMapCenter = $projectionOrigin->project($projectionOrigin); $projectedCorners = array(); $projectedCorners["ne"] = $corners["ne"]->project($projectionOrigin); $projectedCorners["nw"] = $corners["nw"]->project($projectionOrigin); $projectedCorners["sw"] = $corners["sw"]->project($projectionOrigin); $projectedCorners["se"] = $corners["se"]->project($projectionOrigin); $projectedRotatedCorners = array(); $projectedRotatedCorners["ne"] = LinearAlgebraUtil::rotate($projectedCorners["ne"], $projectedMapCenter, $rotation); $projectedRotatedCorners["nw"] = LinearAlgebraUtil::rotate($projectedCorners["nw"], $projectedMapCenter, $rotation); $projectedRotatedCorners["sw"] = LinearAlgebraUtil::rotate($projectedCorners["sw"], $projectedMapCenter, $rotation); $projectedRotatedCorners["se"] = LinearAlgebraUtil::rotate($projectedCorners["se"], $projectedMapCenter, $rotation); $projectedRotatedCorners = array(); $projectedRotatedCorners["ne"] = LinearAlgebraUtil::rotate($projectedCorners["ne"], $projectedMapCenter, $rotation); $projectedRotatedCorners["nw"] = LinearAlgebraUtil::rotate($projectedCorners["nw"], $projectedMapCenter, $rotation); $projectedRotatedCorners["sw"] = LinearAlgebraUtil::rotate($projectedCorners["sw"], $projectedMapCenter, $rotation); $projectedRotatedCorners["se"] = LinearAlgebraUtil::rotate($projectedCorners["se"], $projectedMapCenter, $rotation); $rotatedCorners = array(); $rotatedCorners["nw"] = $projectedRotatedCorners["nw"]->deproject($projectionOrigin); $rotatedCorners["ne"] = $projectedRotatedCorners["ne"]->deproject($projectionOrigin); $rotatedCorners["sw"] = $projectedRotatedCorners["sw"]->deproject($projectionOrigin); $rotatedCorners["se"] = $projectedRotatedCorners["se"]->deproject($projectionOrigin); return $rotatedCorners; }
public static function calculateTransformationMatrixFromTwoCoordinatePairs(Point $p0, Point $q0, Point $p1, Point $q1) { // note that we need to mirror q y pixel values in x axis $angleDifferece = LinearAlgebraUtil::getAngle(new Point($p1->x - $p0->x, $p1->y - $p0->y), new Point($q1->x - $q0->x, -$q1->y + $q0->y)); $lengthQ = LinearAlgebraUtil::distance($q0, $q1); $lengthP = LinearAlgebraUtil::distance($p0, $p1); $scaleFactor = $lengthP == 0 ? 0 : $lengthQ / $lengthP; $cos = cos($angleDifferece); $sin = sin($angleDifferece); // translation to origo in metric space $a = array(); $a[0][0] = 1; $a[0][1] = 0; $a[0][2] = -$p0->x; $a[1][0] = 0; $a[1][1] = 1; $a[1][2] = -$p0->y; $a[2][0] = 0; $a[2][1] = 0; $a[2][2] = 1; // rotation $b = array(); $b[0][0] = $cos; $b[0][1] = -$sin; $b[0][2] = 0; $b[1][0] = $sin; $b[1][1] = $cos; $b[1][2] = 0; $b[2][0] = 0; $b[2][1] = 0; $b[2][2] = 1; // scaling, note that we need to mirror y scale around x axis $c = array(); $c[0][0] = $scaleFactor; $c[0][1] = 0; $c[0][2] = 0; $c[1][0] = 0; $c[1][1] = -$scaleFactor; $c[1][2] = 0; $c[2][0] = 0; $c[2][1] = 0; $c[2][2] = 1; // translation from origo to pixel space $d = array(); $d[0][0] = 1; $d[0][1] = 0; $d[0][2] = $q0->x; $d[1][0] = 0; $d[1][1] = 1; $d[1][2] = $q0->y; $d[2][0] = 0; $d[2][1] = 0; $d[2][2] = 1; return LinearAlgebraUtil::multiply(LinearAlgebraUtil::multiply(LinearAlgebraUtil::multiply($d, $c), $b), $a); }