Home > php教程 > php手册 > 道格拉斯坐标抽稀算法【PHP实现】

道格拉斯坐标抽稀算法【PHP实现】

WBOY
Release: 2016-06-06 19:35:24
Original
1512 people have browsed it

道格拉斯坐标抽稀算法 无 $polyline = "116.621222,41.028553;116.621648,41.029848;.....";$pl = split(";", $polyline);$plstr = "";$flag = 0;$min = 0.0001;for ($j=0; $j count($pl)-1; $j=$j+3) { $xy1 = split(",", $pl[$j]);$x1 = $xy1[0];$y1 = $xy1

道格拉斯坐标抽稀算法
$polyline = "116.621222,41.028553;116.621648,41.029848;.....";
$pl = split(";", $polyline);
$plstr = "";
$flag = 0;
$min = 0.0001;
for ($j=0; $j < count($pl)-1; $j=$j+3) { 
	$xy1 = split(",", $pl[$j]);
	$x1 = $xy1[0];
	$y1 = $xy1[1];
	$xy2 = split(",", $pl[$j+2]);
	$x2 = $xy2[0];
	$y2 = $xy2[1];
	$b = $x1 - $x2;
	$a = $y2 - $y1;
	$c = ($y1 - $y2)*$x1 - $y1*($x1 -$x2);
	$xys = split(",", $pl[$j+1]);
	$d = (abs($a * $xys[0] + $b * $xys[1] + $c)) / (sqrt($a * $a + $b * $b));
	if($d < $min) {
		if($flag == 0)
			$plstr .= $pl[$j+1];
		else
			$plstr .= ";".$pl[$j+1];
		$flag++;
	}
}
$polyline = $plstr;
//希望有技术大神多多提点,帮助我完善代码,万分感谢
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template