我有一个包含坐标的文件,并且想将这些坐标提取到变量x1
, x2
, 中y1
,y2
这样我就可以使用 y = y2-y1 和 x=x2-x1 获得中心线
例如,我想像这样转换文件数据:
points="94.08955764770508,275.3258819580078 99.92155838012695,275.3258819580078 99.92155838012695,281.16587829589844 94.08955764770508,281.16587829589844"
变成这样的变量:
x1 = 94.08955764770508
y1 = 275.3258819580078
x2 = 99.92155838012695
y2 = 275.3258819580078
这是我一直在尝试的代码:
$line = '<polygon id="svg_806" fill-rule="nonzero" fill="black" stroke-linejoin="round" stroke-width="0" points="94.08955764770508,275.3258819580078 99.92155838012695,275.3258819580078 99.92155838012695,281.16587829589844 94.08955764770508,281.16587829589844 "/>';
if (strpos($line,'<polygon') !== false) {
$a = 1;
for ($i=0; $i <= 6; $i++) {
$cordinates = explode('points="', $line);
$cordinates = substr($cordinates[$i], 0, strpos($cordinates[$i], '"'));
foreach(explode(' ', $cordinates) as $value) {
$parts = explode(",", $value);
echo trim($parts[0])."<br/>".trim($parts[1])."<br/>";
}
}
}