Is there a way to rotate objects about a tilted axis in X3D? - rotation

I have wireframe cubes in an X3D file. I am trying to tilt the cubes at a 15 degree axis and rotate them continuously. However, when I try rotating the object, it returns to its original (untilted) position and begins to rotate.
This is the snippet of code that I am using to rotate the one of the cubes.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html;charset=utf-
8'></meta>
<link rel='stylesheet' type='text/css'
href='http://www.x3dom.org/x3dom/release/x3dom.css'></link>
<script type='text/javascript'
src='http://www.x3dom.org/x3dom/release/x3dom.js'></script>
</head>
<body>
<x3d id='someUniqueId' showStat='false' showLog='false' x='0px'
y='0px' width='400px' height='400px'>
<scene>
<navigationInfo avatarSize='0.25 1.75 0.75' headlight='false'
type='"EXAMINE" "ANY"'></navigationInfo>
<background DEF='WO_World' groundColor='0.051 0.051 0.051'
skyColor='0.051 0.051 0.051'></background>
<transform DEF='Cube_TRANSFORM' rotation='-0.735729 0.478906
0.478906 1.87298'>
<transform DEF='Cube_ifs_TRANSFORM'>
<group DEF='group_ME_Cube'>
<shape>
<appearance></appearance>
<indexedFaceSet solid='false' texCoordIndex='0 1 2 3 -1 4 5 6 7 -1 8 9 10 11 -1 12 13 14 15 -1 16 17 18 19 -1 20 21 22 23 -1 24 25 26 27 -1 28 29 30 31 -1 32 33 34 35 -1 36 37 38 39 -1 40 41 42 43 -1 44 45 46 47 -1 48 49 50 51 -1 52 53 54 55 -1 56 57 58 59 -1 60 61 62 63 -1 64 65 66 67 -1 68 69 70 71 -1 72 73 74 75 -1 76 77 78 79 -1 80 81 82 83 -1 84 85 86 87 -1 88 89 90 91 -1 92 93 94 95 -1 96 97 98 99 -1 100 101 102 103 -1 104 105 106 107 -1 108 109 110 111 -1 112 113 114 115 -1 116 117 118 119 -1 120 121 122 123 -1 124 125 126 127 -1 128 129 130 131 -1 132 133 134 135 -1 136 137 138 139 -1 140 141 142 143 -1 144 145 146 147 -1 148 149 150 151 -1 152 153 154 155 -1 156 157 158 159 -1 160 161 162 163 -1 164 165 166 167 -1 168 169 170 171 -1 172 173 174 175 -1 176 177 178 179 -1 180 181 182 183 -1 184 185 186 187 -1 188 189 190 191 -1' coordIndex='16 17 8 0 -1 17 16 1 9 -1 17 18 12 8 -1 18 17 9 13 -1 18 19 4 12 -1 19 18 13 5 -1 19 16 0 4 -1 16 19 5 1 -1 20 21 4 6 -1 21 20 7 5 -1 21 22 12 4 -1 22 21 5 13 -1 22 23 14 12 -1 23 22 13 15 -1 23 20 6 14 -1 20 23 15 7 -1 24 25 12 14 -1 25 24 15 13 -1 25 26 8 12 -1 26 25 13 9 -1 26 27 10 8 -1 27 26 9 11 -1 27 24 14 10 -1 24 27 11 15 -1 28 29 2 10 -1 29 28 11 3 -1 29 30 6 2 -1 30 29 3 7 -1 30 31 14 6 -1 31 30 7 15 -1 31 28 10 14 -1 28 31 15 11 -1 32 33 0 2 -1 33 32 3 1 -1 33 34 4 0 -1 34 33 1 5 -1 34 35 6 4 -1 35 34 5 7 -1 35 32 2 6 -1 32 35 7 3 -1 36 37 8 10 -1 37 36 11 9 -1 37 38 0 8 -1 38 37 9 1 -1 38 39 2 0 -1 39 38 1 3 -1 39 36 10 2 -1 36 39 3 11 -1'>
<coordinate DEF='coords_ME_Cube' point='0.971133 0.971133 0.971133 1.02887 1.02887 1.02887 0.971133 0.971133 -0.971133 1.02887 1.02887 -1.02887 0.971133 -0.971133 0.971133 1.02887 -1.02887 1.02887 0.971133 -0.971133 -0.971133 1.02887 -1.02887 -1.02887 -0.971133 0.971133 0.971133 -1.02887 1.02887 1.02887 -0.971133 0.971133 -0.971133 -1.02887 1.02887 -1.02887 -0.971133 -0.971133 0.971133 -1.02887 -1.02887 1.02887 -0.971133 -0.971133 -0.971133 -1.02887 -1.02887 -1.02887 0.95 0.95 1 -0.95 0.95 1 -0.95 -0.95 1 0.95 -0.95 1 0.95 -1 -0.95 0.95 -1 0.95 -0.95 -1 0.95 -0.95 -1 -0.95 -1 -0.95 -0.95 -1 -0.95 0.95 -1 0.95 0.95 -1 0.95 -0.95 -0.95 0.95 -1 0.95 0.95 -1 0.95 -0.95 -1 -0.95 -0.95 -1 1 0.95 -0.95 1 0.95 0.95 1 -0.95 0.95 1 -0.95 -0.95 -0.95 1 -0.95 -0.95 1 0.95 0.95 1 0.95 0.95 1 -0.95'></coordinate>
<textureCoordinate point='0.625 0.5 0.875 0.5 0.875 0.5 0.625 0.5 0.875 0.5 0.625 0.5 0.625 0.5 0.875 0.5 0.875 0.5 0.875 0.75 0.875 0.75 0.875 0.5 0.875 0.75 0.875 0.5 0.875 0.5 0.875 0.75 0.875 0.75 0.625 0.75 0.625 0.75 0.875 0.75 0.625 0.75 0.875 0.75 0.875 0.75 0.625 0.75 0.625 0.75 0.625 0.5 0.625 0.5 0.625 0.75 0.625 0.5 0.625 0.75 0.625 0.75 0.625 0.5 0.375 0.75 0.625 0.75 0.625 0.75 0.375 0.75 0.625 0.75 0.375 0.75 0.375 0.75 0.625 0.75 0.625 0.75 0.625 1 0.625 1 0.625 0.75 0.625 1 0.625 0.75 0.625 0.75 0.625 1 0.625 1 0.375 1 0.375 1 0.625 1 0.375 1 0.625 1 0.625 1 0.375 1 0.375 1 0.375 0.75 0.375 0.75 0.375 1 0.375 0.75 0.375 1 0.375 1 0.375 0.75 0.375 0 0.625 0 0.625 0 0.375 0 0.625 0 0.375 0 0.375 0 0.625 0 0.625 0 0.625 0.25 0.625 0.25 0.625 0 0.625 0.25 0.625 0 0.625 0 0.625 0.25 0.625 0.25 0.375 0.25 0.375 0.25 0.625 0.25 0.375 0.25 0.625 0.25 0.625 0.25 0.375 0.25 0.375 0.25 0.375 0 0.375 0 0.375 0.25 0.375 0 0.375 0.25 0.375 0.25 0.375 0 0.125 0.5 0.375 0.5 0.375 0.5 0.125 0.5 0.375 0.5 0.125 0.5 0.125 0.5 0.375 0.5 0.375 0.5 0.375 0.75 0.375 0.75 0.375 0.5 0.375 0.75 0.375 0.5 0.375 0.5 0.375 0.75 0.375 0.75 0.125 0.75 0.125 0.75 0.375 0.75 0.125 0.75 0.375 0.75 0.375 0.75 0.125 0.75 0.125 0.75 0.125 0.5 0.125 0.5 0.125 0.75 0.125 0.5 0.125 0.75 0.125 0.75 0.125 0.5 0.375 0.5 0.625 0.5 0.625 0.5 0.375 0.5 0.625 0.5 0.375 0.5 0.375 0.5 0.625 0.5 0.625 0.5 0.625 0.75 0.625 0.75 0.625 0.5 0.625 0.75 0.625 0.5 0.625 0.5 0.625 0.75 0.625 0.75 0.375 0.75 0.375 0.75 0.625 0.75 0.375 0.75 0.625 0.75 0.625 0.75 0.375 0.75 0.375 0.75 0.375 0.5 0.375 0.5 0.375 0.75 0.375 0.5 0.375 0.75 0.375 0.75 0.375 0.5 0.375 0.25 0.625 0.25 0.625 0.25 0.375 0.25 0.625 0.25 0.375 0.25 0.375 0.25 0.625 0.25 0.625 0.25 0.625 0.5 0.625 0.5 0.625 0.25 0.625 0.5 0.625 0.25 0.625 0.25 0.625 0.5 0.625 0.5 0.375 0.5 0.375 0.5 0.625 0.5 0.375 0.5 0.625 0.5 0.625 0.5 0.375 0.5 0.375 0.5 0.375 0.25 0.375 0.25 0.375 0.5 0.375 0.25 0.375 0.5 0.375 0.5 0.375 0.25'></textureCoordinate>
</indexedFaceSet>
</shape>
</group>
</transform>
</transform>
<transform DEF='Light_TRANSFORM' rotation='-0.498084 -0.762016 -0.413815 1.51388' translation='-4.07624 5.90386 1.00545'>
<pointLight DEF='LA_Light' radius='30'></pointLight>
</transform>
<transform DEF='Camera_TRANSFORM' rotation='-0.098233 -0.968789 -0.227591 2.34949' translation='-7.35889 4.95831 -6.92579'>
<viewpoint DEF='CA_Camera' position='-0 -0 100' fieldOfView='0.05'></viewpoint>
</transform>
<timeSensor DEF='clock' cycleInterval='8' loop='true'></timeSensor>
<orientationInterpolator DEF='spinThings' key='0 0.25 0.5 0.75 1' keyValue='0 1 0 0 0 1 0 1.57079 0 1 0 3.14159 0 1 0 4.71239 0 1 0 6.28317'></orientationInterpolator>
<ROUTE fromNode='clock' fromField='fraction_changed' toNode='spinThings' toField='set_fraction'></ROUTE>
<ROUTE fromNode='spinThings' fromField='value_changed' toNode='Cube_TRANSFORM' toField='set_rotation'></ROUTE>
</scene>
</x3d>
</body>
</html>

From the code it is apparent that the transform node with the DEF value of Cube_TRANSFORM is the node that tilts the cubes at the 15 degree axis. However, the second ROUTE statement is replacing this rotation with the interpolated and rotation axis, which for all interpolated values is along the y axis.
If you change the second ROUTE statement so that the toNode value is Cube_ifs_TRANSFORM then the static tilt by 15 degrees will be preserved, and this might be the visual animation you want.

Related

subtract from the previous line

I am trying to subtract the previous group-line from the current group-line one in the 2nd column. For example, the following script is repeating 100s of times.
A
322 0.2
322 0.2
322 0.2
B
455 0.35
455 0.35
455 0.35
C
566 0.92
566 0.92
566 0.92
A
322 0.18
322 0.18
322 0.18
B
455 0.33
455 0.33
455 0.33
C
566 0.99
566 0.99
566 0.99
I want the starting point is A, that means the fraction of 0.2 will be kept the same for the first group and 0.18 for the second group. In other words, C-B then B-A. See the desired output.
A
322 0.2
322 0.2
322 0.2
B
455 0.15
455 0.15
455 0.15
C
566 0.57
566 0.57
566 0.57
A
322 0.18
322 0.18
322 0.18
B
455 0.15
455 0.15
455 0.15
C
566 0.66
566 0.66
566 0.66
I tried this code to print it in the third column but it seems to subtract from the previous line, not previous group.
awk '{$3 = $2 - prev2; prev2 = $2; print;}'
awk to the rescue!
based on the posted input/output and implicit assumptions...
$ awk '/^A/ {ia=1; c=0}
ia {a[c++]=$2}
/^[B-Z]/ {ia=c=0}
!ia && NF>1 {t=$2; $2-=a[++c]; a[c]=t}1' file
A
322 0.2
322 0.2
322 0.2
B
455 0.15
455 0.15
455 0.15
C
566 0.57
566 0.57
566 0.57
A
322 0.18
322 0.18
322 0.18
B
455 0.15
455 0.15
455 0.15
C
566 0.66
566 0.66
566 0.66
the records under each heading can be different, but assumed to the same number of records.
If your real input not represented by this sample you may need to tweak the conditions.
Explanation
/^A/ {ia=1; c=0} if the label starts with A, set A indicator ai, reset counter.
ia {a[c++]=$2} if in A, store values for each record
/^[B-Z]/ {ia=c=0} for other labels, reset in A and counter
!ia && NF>1 {t=$2; $2-=a[++c]; a[c]=t} if not in A and not a label (number of fields more than one), save the numerical value, offset previously saved value for the corresponding record, save the temp value as the new offset value for the record position.
1 print

Discrepancy between classification report and confusion matrix

Maybe I'm reading the classification report or the confusion matrix wrong (or both!), but after having trained my classifier and run on it my test set, I get the following report:
precision recall f1-score support
0 0.71 0.67 0.69 5086
1 0.64 0.54 0.59 2244
2 0.42 0.25 0.31 598
3 0.65 0.22 0.33 262
4 0.53 0.42 0.47 266
5 0.42 0.15 0.22 466
6 0.35 0.25 0.29 227
7 0.07 0.05 0.06 127
8 0.39 0.14 0.21 376
9 0.35 0.25 0.29 167
10 0.25 0.14 0.18 229
avg / total 0.61 0.52 0.55 10048
Which is good and all, but when I create my confusion matrix:
0 1 2 3 4 5 6 7 8 9 10
[[4288 428 80 16 44 58 33 38 47 21 33]
[ 855 1218 54 8 12 17 25 15 15 12 13]
[ 291 72 147 1 12 10 20 2 2 17 24]
[ 173 21 3 57 1 3 0 1 1 1 1]
[ 102 20 4 0 113 0 0 6 4 9 8]
[ 331 40 10 3 7 68 3 0 2 1 1]
[ 104 30 17 0 1 0 56 2 1 10 6]
[ 85 19 4 2 5 0 2 6 4 0 0]
[ 270 29 4 1 6 2 2 7 53 1 1]
[ 63 17 11 0 8 3 14 1 1 42 7]
[ 138 13 19 0 5 2 7 3 6 5 31]]
Am I wrong in assuming, that it has predicted 4288 samples of class label 0 out of a total of 5086, which should result in a recall value of 84.3% (0.843)? But that's not the number the report spits out. The precision seems wrong as well, unless I'm wrong when I calculate the percentage of correct predictions (4288) with the sum of the rest in column 0, which results in 0.563, and not 0.71.
What am I misunderstanding?
It might be worth nothing that I use sklearn's classification_report and confusion_matrix for these.

AWK print group of lines twice if conditions met

I am having difficulties writing an AWK statement that would print out a group of lines twice under specified conditions, with the option to change values in the lines being repeated. For example, if the first field of a row is 11 ($1=11), then I would like to print out that row and the row that follows twice (adjusting the value in the second column ($2).
So far this is what I have, but it does not replicate lines with the first field = to 11 and the following line.
awk '{if(NF<3) print $0; if(NF==3 && $1==11) print $0, 1, 20; if(NF==3 && $1 != 11) print $0, 0, 0; if(NF>3) print $0;}'
Example Input
1 3
6 0.1 99
0.100 0.110 0.111
7 0.4 88
0.200 0.220 0.222
11 0.5 77
0.300 0.330 0.333
2 2
7 0.3 66
0.400 0.440 0.444
11 0.7 55
0.500 0.550 0.555
This is a simplified version of what I would like to do, so let's just say for simplicity I would like the printed NR where $1==11 and following row (NR+1) to have the value in the second column ($2) be half of the original value. Example, for the grouping of rows under the 1 3 section, the value after 11 is 0.5. Ideally, the rows printed out would have the value following 11 to be 0.25.
Ideal Output
1 3
6 0.1 99 0 0
0.100 0.110 0.111
7 0.4 88 0 0
0.200 0.220 0.222
11 0.25 77 1 20
0.300 0.330 0.333
11 0.25 77 1 20
0.300 0.330 0.333
2 2
7 0.3 66 0 0
0.400 0.440 0.444
11 0.35 55 1 20
0.500 0.550 0.555
11 0.35 55 1 20
0.500 0.550 0.555
With GNU awk for gensub() and \s/\S:
$ awk '$1==11{$0=gensub(/^(\s+\S+\s+)\S+/,"\\1"$2/2,1); c=2; s=$0} {print} c&&!--c{print s ORS $0}' file
1 3
6 0.1 99
0.100 0.110 0.111
7 0.4 88
0.200 0.220 0.222
11 0.25 77
0.300 0.330 0.333
11 0.25 77
0.300 0.330 0.333
2 2
7 0.3 66
0.400 0.440 0.444
11 0.35 55
0.500 0.550 0.555
11 0.35 55
0.500 0.550 0.555
You can use the following awk script. (P.S. There are leading and trailing space in your input file. That's why I had to use NF>2 && NF<=5 rather than NF==3.)
BEGIN {
c=0;FS="[ \t]+";OFS=" ";x="";y="";
}
c==2{
print x, 1, 20;
print y;
c=0;
}
NF ==2{
print $0;
}
NF>2 && NF<=5{
if(c==1){
print $0;
y=$0;c=2;next;
}
if($2==11){
print $0, 1, 20;
x=$0;c=1;
}
else print $0;
}
NF>5{
print $0,"hello";
}
END{
if(c==2){
print x, 1, 20;
print y;
}
}

Finding zeros and replacing them with another number in a matrix file by awk

I have a matrix where I want to replace every 0 with 0.1 and depending on how many zeros are replaced the max score in that line will be deducted by number of 0.1s added such that the below matrix will go from,
No line will contain only zeroes, since this is a probability matrix where each line adds up to1. If a highest number occurs more than once (0.5 in this case), then anyone can be changed,and the first line will always be the only one with letters in it,
>ACTTT ASB 0.098
0 0 1 0
0.75 0 0.25 0
0 0 0 1
0 1 0 0
1 0 0 0
1 0 0 0
0 1 0 0
0 1 0 0
to
>ACTTT ASB 0.098
0.1 0.1 0.7 0.1
0.55 0.1 0.25 0.1
0.1 0.1 0.1 0.7
0.1 0.7 0.1 0.1
0.7 0.1 0.1 0.1
0.7 0.1 0.1 0.1
0.1 0.7 0.1 0.1
0.1 0.7 0.1 0.1
I tried to use something like this in a loop from previous answers in here:
while read line ; do echo $line | awk 'NR>1{print gsub(/(^|[[:space:]])0([[:space:]]|$)/,"&")}'; echo $line | awk '{max=$2;for(i=3;i<=NF;i++)if($i>max)max=$i}END{print max}'; done < matrix_file
awk to the rescue!
$ awk -v eps=0.01 'function maxIx() {mI=1;
for(i=1;i<=NF;i++)
if($mI<$i)mI=i;
return mI}
NR>1{mX=maxIx();
for(i=1;i<=NF;i++)
if($i==0) {$i=eps;$mX-=eps}}1' file
>ACTTT ASB 0.098
0.01 0.01 0.97 0.01
0.73 0.01 0.25 0.01
0.01 0.01 0.01 0.97
0.01 0.97 0.01 0.01
0.97 0.01 0.01 0.01
0.97 0.01 0.01 0.01
0.01 0.97 0.01 0.01
0.01 0.97 0.01 0.01
defined eps, as long as you have a sensible value it should work fine, but doesn't check for going below zero.

remove lines with awk when the value is smaller than

Hello I have this input:
10579 5 2.0 5 100 0 20 0 80 0 20 0.72
10586 5 2.0 5 100 0 20 0 40 20 40 1.52
10856 4 3.2 4 100 0 26 0 69 30 0 0.89
11049 6 12.2 6 65 26 48 14 36 49 0 1.43
11041 2 26.0 2 70 37 20 8 43 47 0 1.34
11012 5 3.0 5 90 9 25 0 56 43 0 0.99
11041 5 3.0 5 9 25 0 56 43 0 0.99
11096 6 2.2 6 100 0 26 15 30 53 0 1.42
11194 1 28.0 1 93 6 51 0 3 96 0 0.22
11236 5 2.4 5 0 24 0 41 58 0 0.98
11981 1 10.0 1 50 18 15 0 9 0 90 0.44
12184 5 2.2 5 100 0 22 18 0 54 27 1.44
12482 4 2.5 4 100 0 20 20 0 80 0 0.72
12627 5 2.2 5 100 0 22 18 0 81 0 0.68
I want to remove lines when the column 5 is smaller than 85. I can do that with awk (awk '$5 > 85') but I want to keep lines when $5 is empty (line 7 and 10). So my output will be like this:
10579 5 2.0 5 100 0 20 0 80 0 20 0.72
10586 5 2.0 5 100 0 20 0 40 20 40 1.52
10579 5 2.0 5 100 0 20 0 80 0 20 0.72
10586 5 2.0 5 100 0 20 0 40 20 40 1.52
10856 4 3.2 4 100 0 26 0 69 30 0 0.89
11012 5 3.0 5 90 9 25 0 56 43 0 0.99
11041 5 3.0 5 9 25 0 56 43 0 0.99
11096 6 2.2 6 100 0 26 15 30 53 0 1.42
11194 1 28.0 1 93 6 51 0 3 96 0 0.22
11236 5 2.4 5 0 24 0 41 58 0 0.78
12184 5 2.2 5 100 0 22 18 0 54 27 1.44
12482 4 2.5 4 100 0 20 20 0 80 0 0.72
12627 5 2.2 5 100 0 22 18 0 81 0 0.68
awk '$5 > 85' is removing also those line. Any help? Thanks
you have to set your field delimiter to a single space, otherwise awk wouldn't know which field is missing
$ awk -F' ' '$5>85' file
10579 5 2.0 5 100 0 20 0 80 0 20 0.72
10586 5 2.0 5 100 0 20 0 40 20 40 1.52
10856 4 3.2 4 100 0 26 0 69 30 0 0.89
11012 5 3.0 5 90 9 25 0 56 43 0 0.99
11096 6 2.2 6 100 0 26 15 30 53 0 1.42
11194 1 28.0 1 93 6 51 0 3 96 0 0.22
12184 5 2.2 5 100 0 22 18 0 54 27 1.44
12482 4 2.5 4 100 0 20 20 0 80 0 0.72
12627 5 2.2 5 100 0 22 18 0 81 0 0.68

Resources