File "graph3.php"

Full path: /www/ansys/ttest/accmes/graph3.php
File size: 16.96 KiB (17368 bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Back

<?php
$indexURL = "./index.php";
$position = isset($_POST["position"]) ? htmlspecialchars($_POST["position"]) : "";

$sepPosition = split(",", $position);
$len = count($sepPosition);

$imgFname = "./img/acc_". md5(uniqid(rand(), true)). ".png";

// 読み込むファイル名、戻る場所を決める
$dataFname = "/";
$returnPosition = "";
for($iCount = 0; $iCount < $len; $iCount++)
{
	if ($iCount > 0)
	{
		$dataFname .= "/";
		if ($iCount < $len - 1)
			$returnPosition .= ",";
	}
	$dataFname .= $sepPosition[$iCount];
	if ($iCount < $len - 1)
		$returnPosition .= $sepPosition[$iCount];
}

try
{
	$img = imagecreate(1350, 610);
	$font = "/www/ansys/config/fonts/ipagp.ttf";
	
	// color一覧
	$black = imagecolorallocate($img, 0x00, 0x00, 0x00);
	$white = imagecolorallocate($img, 0xff, 0xff, 0xff);
	//$gmain = imagecolorallocate($img, 0xff, 0xff, 0xff);
	$gmain = imagecolorallocate($img, 0x00, 0x00, 0x00);
	$gsub = imagecolorallocate($img, 0x69, 0x69, 0x69);
	//$back = imagecolorallocate($img, 0x00, 0x00, 0x00);
	$back = imagecolorallocate($img, 0xff, 0xff, 0xff);
	
	$cpx = array(imagecolorallocate($img, 0xff, 0x00, 0x00), imagecolorallocate($img, 0xff, 0x69, 0xb4), imagecolorallocate($img, 0xff, 0xb6, 0xc1));
	//$clx = imagecolorallocate($img, 0xff, 0x63, 0x47);
	$cpy = array(imagecolorallocate($img, 0x00, 0xff, 0x00), imagecolorallocate($img, 0x22, 0x8b, 0x22), imagecolorallocate($img, 0x3c, 0xb3, 0x71));
	//$cly = imagecolorallocate($img, 0x22, 0x8b, 0x57);
	$cpz = array(imagecolorallocate($img, 0x00, 0x00, 0xff), imagecolorallocate($img, 0x00, 0xbf, 0xff), imagecolorallocate($img, 0x87, 0xce, 0xeb));
	//$clz = imagecolorallocate($img, 0x19, 0x19, 0x70);
	$cpv = array(imagecolorallocate($img, 0xff, 0xd7, 0x00), imagecolorallocate($img, 0xda, 0xa5, 0x20), imagecolorallocate($img, 0xa0, 0x52, 0x2d));
	//$clv = imagecolorallocate($img, 0xff, 0xa5, 0x00);
	
	$blx = imagecolorallocate($img, 0xff, 0xc0, 0xcb);
	$bly = imagecolorallocate($img, 0x98, 0xfb, 0x98);
	$blz = imagecolorallocate($img, 0xad, 0xd8, 0xe6);
	
	$cpc = imagecolorallocate($img, 0xb2, 0x22, 0x22);
	
	imagefilledrectangle($img, 0, 0, 1350, 610, $back);
	imagesetthickness($img, 1);
	
	// 基準軸
	imageline($img, 50, 50, 50, 550, $gmain);
	imageline($img, 1310, 50, 1310, 550, $gmain);
	imageline($img, 50, 50, 45, 55, $gmain);
	imageline($img, 50, 50, 55, 55, $gmain);
	imageline($img, 50, 550, 1310, 550, $gmain);
	imageline($img, 1310, 550, 1305, 545, $gmain);
	imageline($img, 1310, 550, 1305, 555, $gmain);
	
	imageline($img, 50, 238, 1310, 238, $cpc);
	
	$yparse = 42;
	// 補助軸
	for($iCount = 1; $iCount < $yparse; $iCount++)
	{
		//imagettftext($img, 7, 0, 50 + (60 * $iCount) - 3, 565, $gmain, $font, mb_convert_encoding($iCount, "UTF-8", "auto"));
		imageline($img, 50 + (60 * $iCount), 50, 50 + (60 * $iCount), 550, $gsub);
		imageline($img, 50 + (60 * $iCount), 545, 50 + (60 * $iCount), 555, $gmain);
	}
	imagettftext($img, 8, 0, 650, 585, $gmain, $font, mb_convert_encoding("経過秒[sec]", "UTF-8", "auto"));
	
	imageline($img, 45, 300, 1310, 300, $gmain);
	imagettftext($img, 7, 0, 33, 300 + 4, $gmain, $font, mb_convert_encoding("0", "UTF-8", "auto"));
	for($iCount = 1; $iCount < 10; $iCount++)
	{
		imageline($img, 50, 300 + ($iCount * 25), 1310, 300 + ($iCount * 25), $gsub);
		imageline($img, 45, 300 + ($iCount * 25), 55, 300 + ($iCount * 25), $gmain);
		imagettftext($img, 7, 0, 30, 300 + ($iCount * 25) + 4, $gmain, $font, mb_convert_encoding("-". $iCount, "UTF-8", "auto"));
		
		imageline($img, 50, 300 - ($iCount * 25), 1310, 300 - ($iCount * 25), $gsub);
		imageline($img, 45, 300 - ($iCount * 25), 55, 300 - ($iCount * 25), $gmain);
		imagettftext($img, 7, 0, 28, 300 - ($iCount * 25) + 4, $gmain, $font, mb_convert_encoding("+". $iCount, "UTF-8", "auto"));
	}
	imagettftext($img, 8, 90, 15, 320, $gmain, $font, mb_convert_encoding("加速度値", "UTF-8", "auto"));
	
	// 外積値での軸メモリ
	for($iCount = 0; $iCount < 21; $iCount++)
	{
		imagettftext($img, 7, 0, 1320, 554 - ($iCount * 25), $gmain, $font, mb_convert_encoding($iCount * 2, "UTF-8", "auto"));
	}
	
	// 凡例(長期)
	imagefilledellipse($img, 260, 30, 6, 6, $cpx[0]);
	imagettftext($img, 8, 0, 240, 20, $gmain, $font, mb_convert_encoding("X(長期)", "UTF-8", "auto"));
	imagefilledellipse($img, 330, 30, 6, 6, $cpy[0]);
	imagettftext($img, 8, 0, 310, 20, $gmain, $font, mb_convert_encoding("Y(長期)", "UTF-8", "auto"));
	imagefilledellipse($img, 400, 30, 6, 6, $cpz[0]);
	imagettftext($img, 8, 0, 380, 20, $gmain, $font, mb_convert_encoding("Z(長期)", "UTF-8", "auto"));
	imagefilledellipse($img, 470, 30, 6, 6, $cpv[0]);
	imagettftext($img, 8, 0, 435, 20, $gmain, $font, mb_convert_encoding("3軸合成(長期)", "UTF-8", "auto"));
	// 凡例(中期)
	imagefilledellipse($img, 260 + 300, 30, 6, 6, $cpx[1]);
	imagettftext($img, 8, 0, 240 + 300, 20, $gmain, $font, mb_convert_encoding("X(中期)", "UTF-8", "auto"));
	imagefilledellipse($img, 330 + 300, 30, 6, 6, $cpy[1]);
	imagettftext($img, 8, 0, 310 + 300, 20, $gmain, $font, mb_convert_encoding("Y(中期)", "UTF-8", "auto"));
	imagefilledellipse($img, 400 + 300, 30, 6, 6, $cpz[1]);
	imagettftext($img, 8, 0, 380 + 300, 20, $gmain, $font, mb_convert_encoding("Z(中期)", "UTF-8", "auto"));
	imagefilledellipse($img, 470 + 300, 30, 6, 6, $cpv[1]);
	imagettftext($img, 8, 0, 435 + 300, 20, $gmain, $font, mb_convert_encoding("3軸合成(中期)", "UTF-8", "auto"));
	// 凡例(短期)
	imagefilledellipse($img, 260 + 600, 30, 6, 6, $cpx[2]);
	imagettftext($img, 8, 0, 240 + 600, 20, $gmain, $font, mb_convert_encoding("X(短期)", "UTF-8", "auto"));
	imagefilledellipse($img, 330 + 600, 30, 6, 6, $cpy[2]);
	imagettftext($img, 8, 0, 310 + 600, 20, $gmain, $font, mb_convert_encoding("Y(短期)", "UTF-8", "auto"));
	imagefilledellipse($img, 400 + 600, 30, 6, 6, $cpz[2]);
	imagettftext($img, 8, 0, 380 + 600, 20, $gmain, $font, mb_convert_encoding("Z(短期)", "UTF-8", "auto"));
	imagefilledellipse($img, 470 + 600, 30, 6, 6, $cpv[2]);
	imagettftext($img, 8, 0, 435 + 600, 20, $gmain, $font, mb_convert_encoding("3軸合成(短期)", "UTF-8", "auto"));
	// 凡例(外積)
	imagefilledellipse($img, 560 + 600, 30, 6, 6, $cpc);
	imagettftext($img, 8, 0, 550 + 600, 20, $gmain, $font, mb_convert_encoding("基準値外積", "UTF-8", "auto"));
	
	// 各軸の最大最小
	$xmin = array("pix" => 0, "val" => 0);
	$xmax = array("pix" => 1260, "val" => 0);
	$ymin = array("pix" => 500, "val" => -10.0);
	$ymax = array("pix" => 0, "val" => 10.0);
	
	$ymin2 = array("pix" => 500, "val" => 0);
	$ymax2 = array("pix" => 0, "val" => 40);
	
	$dx = 0;
	$dy = number_format(($ymax["val"] - $ymin["val"]) / 500, 10);
	$dy2 = number_format(($ymax2["val"] - $ymin2["val"]) / 500, 10);
	
	$ard = array();
	
	// データを取得
	$index = 0;
	$fp = fopen($dataFname, "r");
	if ($fp != NULL)
	{
		while(!feof($fp))
		{
			$line = trim(fgets($fp));
			if (strcmp($line, "") != 0)
			{
				$stac = split(",", $line);
				if (strcmp(substr($stac[0], 0, 1), "#") == 0)
				{
					$gacc["x"] = $stac[1];
					$gacc["y"] = $stac[2];
					$gacc["z"] = $stac[3];
					
					imageline($img, 50, 500 - (($stac[1] - $ymin["val"]) / $dy) + 50, 1310, (500 - ($stac[1] - $ymin["val"]) / $dy) + 50, $blx);
					imageline($img, 50, 500 - (($stac[2] - $ymin["val"]) / $dy) + 50, 1310, (500 - ($stac[2] - $ymin["val"]) / $dy) + 50, $bly);
					imageline($img, 50, 500 - (($stac[3] - $ymin["val"]) / $dy) + 50, 1310, (500 - ($stac[3] - $ymin["val"]) / $dy) + 50, $blz);
					
					imagettftext($img, 8, 0, 20, 600, $gmain, $font, mb_convert_encoding("基準値(x):". $gacc["x"], "UTF-8", "auto"));
					imagettftext($img, 8, 0, 120, 600, $gmain, $font, mb_convert_encoding("基準値(y):". $gacc["y"], "UTF-8", "auto"));
					imagettftext($img, 8, 0, 220, 600, $gmain, $font, mb_convert_encoding("基準値(z):". $gacc["z"], "UTF-8", "auto"));
					continue;
				}
				if ($index == 0)
				{
					$xmin["val"] = floor(($stac[0] / 1000.0)) * 1000.0;
					$xmax["val"] = $xmin["val"] + ($yparse * 1000);
					$dx = number_format($yparse * 1000 / 1260, 10);
					for($iCount = 0; $iCount < 22; $iCount++)
						imagettftext($img, 7, 0, 50 - $yparse + ($iCount * 60), 570, $gmain, $font, mb_convert_encoding(date("H:i:s", $xmin["val"] / 1000.0 + ($iCount)), "UTF-8", "auto"));
				}
				$ard[$index]["msec"] = $stac[0];
				$ard[$index]["x"] = $stac[1];
				$ard[$index]["y"] = $stac[2];
				$ard[$index]["z"] = $stac[3];
				$ard[$index]["v"] = sqrt(($ard[$index]["x"] * $ard[$index]["x"]) + ($ard[$index]["y"] * $ard[$index]["y"]) + ($ard[$index]["z"] * $ard[$index]["z"]));
				$ard[$index]["long"] = array("index" => 0, "x" => 0, "y" => 0, "z" => 0, "v" => 0);
				$ard[$index]["middle"] = array("index" => 0, "x" => 0, "y" => 0, "z" => 0, "v" => 0);
				$ard[$index]["short"] = array("index" => 0, "x" => 0, "y" => 0, "z" => 0, "v" => 0);
				
				// 移動平均の算出
				$iid = $index;
				while(true)
				{
					$diff = $ard[$index]["msec"] - $ard[$iid]["msec"];
					if ($diff <= 1000)
					{
						$ard[$index]["long"]["index"]++;
						$ard[$index]["long"]["x"] += $ard[$iid]["x"];
						$ard[$index]["long"]["y"] += $ard[$iid]["y"];
						$ard[$index]["long"]["z"] += $ard[$iid]["z"];
						$ard[$index]["long"]["v"] += $ard[$iid]["v"];
						if ($diff <= 200)
						{
							$ard[$index]["middle"]["index"]++;
							$ard[$index]["middle"]["x"] += $ard[$iid]["x"];
							$ard[$index]["middle"]["y"] += $ard[$iid]["y"];
							$ard[$index]["middle"]["z"] += $ard[$iid]["z"];
							$ard[$index]["middle"]["v"] += $ard[$iid]["v"];
							if ($diff <= 40)
							{
								$ard[$index]["short"]["index"]++;
								$ard[$index]["short"]["x"] += $ard[$iid]["x"];
								$ard[$index]["short"]["y"] += $ard[$iid]["y"];
								$ard[$index]["short"]["z"] += $ard[$iid]["z"];
								$ard[$index]["short"]["v"] += $ard[$iid]["v"];
							}
						}
					}
					else
					{
						break;
					}
					$iid--;
					if ($iid < 0)
						break;
				}
				$ard[$index]["long"]["x"] = $ard[$index]["long"]["x"] / $ard[$index]["long"]["index"];
				$ard[$index]["long"]["y"] = $ard[$index]["long"]["y"] / $ard[$index]["long"]["index"];
				$ard[$index]["long"]["z"] = $ard[$index]["long"]["z"] / $ard[$index]["long"]["index"];
				$ard[$index]["long"]["v"] = $ard[$index]["long"]["v"] / $ard[$index]["long"]["index"];
				$ard[$index]["middle"]["x"] = $ard[$index]["middle"]["x"] / $ard[$index]["middle"]["index"];
				$ard[$index]["middle"]["y"] = $ard[$index]["middle"]["y"] / $ard[$index]["middle"]["index"];
				$ard[$index]["middle"]["z"] = $ard[$index]["middle"]["z"] / $ard[$index]["middle"]["index"];
				$ard[$index]["middle"]["v"] = $ard[$index]["middle"]["v"] / $ard[$index]["middle"]["index"];
				$ard[$index]["short"]["x"] = $ard[$index]["short"]["x"] / $ard[$index]["short"]["index"];
				$ard[$index]["short"]["y"] = $ard[$index]["short"]["y"] / $ard[$index]["short"]["index"];
				$ard[$index]["short"]["z"] = $ard[$index]["short"]["z"] / $ard[$index]["short"]["index"];
				$ard[$index]["short"]["v"] = $ard[$index]["short"]["v"] / $ard[$index]["short"]["index"];
				
				// add 2013/12/12 外積
				//$ard[$index]["c"] = pow(
				//(($gacc["y"] * ($ard[$index]["short"]["z"] + $gacc["z"]) - $gacc["z"] * ($ard[$index]["short"]["y"] + $gacc["y"])) * ($gacc["y"] * ($ard[$index]["short"]["z"] + $gacc["z"]) - $gacc["z"] * ($ard[$index]["short"]["y"] + $gacc["y"]))) + 
				//(($gacc["z"] * ($ard[$index]["short"]["x"] + $gacc["x"]) - $gacc["x"] * ($ard[$index]["short"]["z"] + $gacc["z"])) * ($gacc["z"] * ($ard[$index]["short"]["x"] + $gacc["x"]) - $gacc["x"] * ($ard[$index]["short"]["z"] + $gacc["z"]))) + 
				//(($gacc["x"] * ($ard[$index]["short"]["y"] + $gacc["y"]) - $gacc["y"] * ($ard[$index]["short"]["x"] + $gacc["x"])) * ($gacc["x"] * ($ard[$index]["short"]["y"] + $gacc["y"]) - $gacc["y"] * ($ard[$index]["short"]["x"] + $gacc["x"])))
				//, 0.5);
				$ard[$index]["c"] = pow(
				(0 - ($ard[$index]["v"] * $ard[$index]["short"]["y"])) * (0 - ($ard[$index]["v"] * $ard[$index]["short"]["y"])) + 
				(($ard[$index]["v"] * $ard[$index]["short"]["x"]) - 0) * (($ard[$index]["v"] * $ard[$index]["short"]["x"]) - 0) + 
				((0 - 0) * (0 - 0))
				, 0.5);
				//print $ard[$index]["c"]. "<br>";
				
				$p = array();
				$p["x"] = ($stac[0] - $xmin["val"]) / $dx;
				$p["y"]["long"]["x"] = 500 - ($ard[$index]["long"]["x"] - $ymin["val"]) / $dy;
				$p["y"]["long"]["y"] = 500 - ($ard[$index]["long"]["y"] - $ymin["val"]) / $dy;
				$p["y"]["long"]["z"] = 500 - ($ard[$index]["long"]["z"] - $ymin["val"]) / $dy;
				$p["y"]["long"]["v"] = 500 - ($ard[$index]["long"]["v"] - $ymin["val"]) / $dy;
				
				$p["y"]["middle"]["x"] = 500 - ($ard[$index]["middle"]["x"] - $ymin["val"]) / $dy;
				$p["y"]["middle"]["y"] = 500 - ($ard[$index]["middle"]["y"] - $ymin["val"]) / $dy;
				$p["y"]["middle"]["z"] = 500 - ($ard[$index]["middle"]["z"] - $ymin["val"]) / $dy;
				$p["y"]["middle"]["v"] = 500 - ($ard[$index]["middle"]["v"] - $ymin["val"]) / $dy;
				
				$p["y"]["short"]["x"] = 500 - ($ard[$index]["short"]["x"] - $ymin["val"]) / $dy;
				$p["y"]["short"]["y"] = 500 - ($ard[$index]["short"]["y"] - $ymin["val"]) / $dy;
				$p["y"]["short"]["z"] = 500 - ($ard[$index]["short"]["z"] - $ymin["val"]) / $dy;
				$p["y"]["short"]["v"] = 500 - ($ard[$index]["short"]["v"] - $ymin["val"]) / $dy;
				
				imagefilledellipse($img, $p["x"] + 50, $p["y"]["short"]["x"] + 50, 3, 3, $cpx[2]);
				imagefilledellipse($img, $p["x"] + 50, $p["y"]["short"]["y"] + 50, 3, 3, $cpy[2]);
				imagefilledellipse($img, $p["x"] + 50, $p["y"]["short"]["z"] + 50, 3, 3, $cpz[2]);
				imagefilledellipse($img, $p["x"] + 50, $p["y"]["short"]["v"] + 50, 3, 3, $cpv[2]);
				
				imagefilledellipse($img, $p["x"] + 50, $p["y"]["middle"]["x"] + 50, 3, 3, $cpx[1]);
				imagefilledellipse($img, $p["x"] + 50, $p["y"]["middle"]["y"] + 50, 3, 3, $cpy[1]);
				imagefilledellipse($img, $p["x"] + 50, $p["y"]["middle"]["z"] + 50, 3, 3, $cpz[1]);
				imagefilledellipse($img, $p["x"] + 50, $p["y"]["middle"]["v"] + 50, 3, 3, $cpv[1]);
				
				imagefilledellipse($img, $p["x"] + 50, $p["y"]["long"]["x"] + 50, 3, 3, $cpx[0]);
				imagefilledellipse($img, $p["x"] + 50, $p["y"]["long"]["y"] + 50, 3, 3, $cpy[0]);
				imagefilledellipse($img, $p["x"] + 50, $p["y"]["long"]["z"] + 50, 3, 3, $cpz[0]);
				imagefilledellipse($img, $p["x"] + 50, $p["y"]["long"]["v"] + 50, 3, 3, $cpv[0]);
				
				// 2013/12/12 外積値の表示
				$p["c"] = 500 - ($ard[$index]["c"] - $ymin2["val"]) / $dy2;
				imagefilledellipse($img, $p["x"] + 50, $p["c"] + 50, 3, 3, $cpc);
				
//				$p = array();
//				$p["x"] = ($stac[0] - $xmin["val"]) / $dx;
//				$p["y"]["x"] = 500 - ($stac[1] - $ymin["val"]) / $dy;
//				$p["y"]["y"] = 500 - ($stac[2] - $ymin["val"]) / $dy;
//				$p["y"]["z"] = 500 - ($stac[3] - $ymin["val"]) / $dy;
//				$p["y"]["v"] = 500 - (sqrt(
//				($stac[1] * $stac[1]) + ($stac[2] * $stac[2]) + ($stac[3] * $stac[3])
//				) - $ymin["val"]) / $dy;
//				imagefilledellipse($img, $p["x"] + 50, $p["y"]["x"] + 50, 3, 3, $cpx);
//				imagefilledellipse($img, $p["x"] + 50, $p["y"]["y"] + 50, 3, 3, $cpy);
//				imagefilledellipse($img, $p["x"] + 50, $p["y"]["z"] + 50, 3, 3, $cpz);
//				imagefilledellipse($img, $p["x"] + 50, $p["y"]["v"] + 50, 3, 3, $cpv);
//				//print $stac["1"]. ":". $p["y"]["x"]. "<br />";
//				if ($index > 0)
//				{
//					imageline($img, $ap["x"] + 50, $ap["y"]["x"] + 50, $p["x"] + 50, $p["y"]["x"] + 50, $clx);
//					imageline($img, $ap["x"] + 50, $ap["y"]["y"] + 50, $p["x"] + 50, $p["y"]["y"] + 50, $cly);
//					imageline($img, $ap["x"] + 50, $ap["y"]["z"] + 50, $p["x"] + 50, $p["y"]["z"] + 50, $clz);
//					imageline($img, $ap["x"] + 50, $ap["y"]["v"] + 50, $p["x"] + 50, $p["y"]["v"] + 50, $clv);
//				}
				
				if ($index > 0)
				{
					imageline($img, $ap["x"] + 50, $ap["c"] + 50, $p["x"] + 50, $p["c"] + 50, $cpc);
				}
				
				$ap = $p;
				$index++;
			}
		}
		fclose($fp);
	}
	//print_r($ard);
	//print $ard[992]["long"]["x"];
	imagepng($img, $imgFname);
	imagedestroy($img);
}
catch(Exception $exc)
{
	print $exc->getMessage(). "<br />";
}

print "<!DOCTYPE html>";
print "<html>";

print "<head>";
print "<meta chaset=\"utf-8\">";
print "<link rel=\"stylesheet\" type=\"text/css\" href=\"./css/style.css\">";
print "<title>";
print "加速度グラフ";
print "</title>";
print "</head>";

print "<body>";

print "<img src=\"". $imgFname. "?t=$now_t\">";
print "<br />";
print "<form name=\"form_return\" method=\"post\" action=\"". $indexURL. "\" style=\"display:inline\">";
print "<a href=\"javascript:form_return.submit()\">戻る</a>";
print "<input type=\"hidden\" name=\"position\" value=\"". $returnPosition. "\">";
print "</form>";

print "&nbsp;&nbsp;&nbsp;";

print "<form name=\"move_graph\" method=\"post\" action=\"./graph.php\" style=\"display:inline\">";
print "<a href=\"javascript:move_graph.submit()\">瞬時値を見る</a>";
print "<input type=\"hidden\" name=\"position\" value=\"". $position. "\">";
print "</form>";

print "&nbsp;&nbsp;&nbsp;";

print "<form name=\"move_graph2\" method=\"post\" action=\"./graph2.php\" style=\"display:inline\">";
print "<a href=\"javascript:move_graph2.submit()\">移動平均値を見る</a>";
print "<input type=\"hidden\" name=\"position\" value=\"". $position. "\">";
print "</form>";

print "</body>";
print "</html>";

PHP File Manager