-
Notifications
You must be signed in to change notification settings - Fork 1
/
tmcutils.php
89 lines (83 loc) · 1.58 KB
/
tmcutils.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
function nonempty($s)
{
return($s !== "");
}
function combine($k, $v)
{
return "$k = $v";
}
function array_cmt($a)
{
$v = array_filter($a, "nonempty");
$k = array_keys($v);
$c = array_map("combine", $k, $v);
return implode("\n", $c);
}
function array_desc($a)
{
if($a['class'] == 'P')
$data = array($a['junctionnumber'], $a['rnid'], $a['n1id'], $a['n2id']);
else if($a['class'] == 'L')
$data = array($a['roadnumber'], $a['rnid'], $a['n1id'], $a['n2id']);
else
$data = array($a['nid']);
return implode(" ", array_filter($data, "nonempty"));
}
function calc_angle($neg, $data, $pos)
{
return rad2deg(atan2((float)($neg['xcoord'] - $pos['xcoord']) * cos(deg2rad($data['ycoord'])), (float)($neg['ycoord'] - $pos['ycoord'])));
}
function line_angles($array)
{
$angles = array();
$pp = $p = false;
foreach($array as $data)
{
if(!$p)
{
$p = $data;
}
else if(!$pp)
{
$angles[] = calc_angle($p, $data, $data);
$pp = $p;
$p = $data;
}
else
{
$angles[] = calc_angle($pp, $p, $data);
$pp = $p;
$p = $data;
}
}
$angles[] = calc_angle($pp, $p, $p);
return $angles;
}
function ring_angles($array)
{
$angles = array();
$pp = $p = false;
foreach($array as $data)
{
if(!$p)
{
$p = $data;
}
else if(!$pp)
{
$angles[] = calc_angle($array[count($array) - 1], $p, $data);
$pp = $p;
$p = $data;
}
else
{
$angles[] = calc_angle($pp, $p, $data);
$pp = $p;
$p = $data;
}
}
$angles[] = calc_angle($pp, $p, $array[0]);
return $angles;
}
?>