Searching mathematical algorithm for vector calculation - math

I have given directions of 3D Objects like this:
Direction1:
X-Vector:
X_X: 1
X_Y: 0
X_Z: 0
Y-Vector:
Y_X: 0
Y_Y: 1
Y_Z: 0
Z-Vector:
Z_X: 0
Z_Y: 0
Z_Z: 1
Direction2:
X-Vector:
X_X: 0
X_Y: 0
X_Z: 1
Y-Vector:
Y_X: 0
Y_Y: -1
Y_Z: 0
Z-Vector:
Z_X: 1
Z_Y: 0
Z_Z: 0
That looks like this (Direction1 on the left, Direction2 on the right):
I have to filter out the information about the rotation from direction1 to direction2 now.
There are algorithms f.e. which calculates the rotation of vector1 to vector 2, but here i have 3 vectors and i don't know, how i can calculate the euler rotation angle here.
I thought about summarizing the 3 Vectors to 1, f.e. picture 1 would be (1,1,1) and pic2 would be (1,-1,1), but the problem here is that the information, which axe points in which direction gets lost.
Has somebody an idea?

Seems that you want to find affine transformation that transforms one triplet of non-coplanar vectors into another triplet.
Make matrices A and B and unknown rotation matrix M.
Here column vector like x1 y1 z1 is your X_X X_Y X_Z and so on.
M * A = B
|x1 x2 x3 0| |x1` x2` x3` 0|
M * |y1 y2 y3 0| = |y1` y2` y3` 0|
|z1 z2 z3 0| |z1` z2` z3` 0|
|1 1 1 1| |1 1 1 1|
find inverse matrix InvA for the A and multiply both sides by IA
M * A * InvA = B * InvA
M * |1 |= B * InvA
M = B * InvA
Now you have matrix M needed to transform vectors.
Rotation about 5,0,0
|1 0 0 -5| |1 0 0 5|
M' = |0 1 0 0| * M * |0 1 0 0|
|0 0 1 0| |0 0 1 0|
|0 0 0 1| |0 0 0 1|

Related

How to make plot a curve in Scilab?

Use param3d to plot a curve C1(u)=Au2+Bu+C, which passes through
(0,0,0) at u=0,
(1,0,0)at u=1,
(1/2,1/2, 0) at u=0.5.
Have to use param3d .
Just write down the equations, using matrix block form you have
| 0 0 1 | | A | | 0 0 0 |
| 1 1 1 | * | B | = | 1 0 0 |
| 1/4 1/2 1 | | C | | 1/2 1/2 0 |
hence you just have to solve this equation for the [A;B;C] matrix then extract A,B,C and plot the curve
ABC = [0 0 1;1 1 1;1/4 1/2 1] \ [0 0 0;1 0 0;1/2 1/2 0];
A = ABC(1,:);
B = ABC(2,:);
C = ABC(3,:);
u = linspace(0,1,100);
C1 = A'*u.^2+B'*u+C'*ones(u);
param3d(C1(1,:),C1(2,:),C1(3,:));
It is easy to see in advance that C=(0,0,0) here, but the above method is general.

R Dummies for subsetting data

I have data on the GPS bearing(0-360 degrees) from one place to many other places(A-Z)
I want to create 4 columns of dummy variables, specifically: 0-89 degrees, 90-179 degrees, 180-269 degrees, and 270-360 degrees. So that each observation (A-Z) will have a 0 in three of the columns, and a 1 in the column that corresponds to its bearing.
Thanks all!
You can use model.matrix in combination with cut. cut creates a factor with the grouping and model.matrix generates the dummy data frame.
x <- c(0, 67, 90, 183, 352)
res <- model.matrix(~ cut(x, c(-1, 89, 179, 269, 360))-1)
the output is then
cut(GPS$gps_bearing, c(-1, 89, 179, 269, 360))(-1,89]
1 1
2 1
3 0
4 0
5 0
cut(GPS$gps_bearing, c(-1, 89, 179, 269, 360))(89,179]
1 0
2 0
3 1
4 0
5 0
cut(GPS$gps_bearing, c(-1, 89, 179, 269, 360))(179,269]
1 0
2 0
3 0
4 1
5 0
cut(GPS$gps_bearing, c(-1, 89, 179, 269, 360))(269,360]
1 0
2 0
3 0
4 0
5 1
attr(,"assign")
[1] 1 1 1 1
attr(,"contrasts")
attr(,"contrasts")$`cut(GPS$gps_bearing, c(-1, 89, 179, 269, 360))`
[1] "contr.treatment"
Now the columns names aren't pretty and should probably be changed, but the matrix is as you'd want.
Step1: Binning the temperature using cut
Step2: Creatinng dummies by createDummyFeatures (present in mlr library)
install.packages("mlr")
library(mlr)
a <- data.frame(cbind(state=c("a","b","c","d","e","f","g"),
temperature=c(0,12,89,90,180,350,360)))
a$temperature <- as.numeric(levels(a$temperature))[a$temperature]
a$bucket <- cut(a$temperature,c(0,89,179,269,360),
labels=c("0-89","90-179","180-269","270-360"),include.lowest=TRUE)
createDummyFeatures(a,cols="bucket")
My Output:
|sno |state |temperature |bucket.0.89 |bucket.90.179 |bucket.180.269 |bucket.270.360
|1 |a |0 |1 |0 |0 |0
|2 |b |12 |1 |0 |0 |0
|3 |c |89 |1 |0 |0 |0
|4 |d |90 |0 |1 |0 |0
|5 |e |180 |0 |0 |1 |0
|6 |f |350 |0 |0 |0 |1
|7 |g |360 |0 |0 |0 |1
Let me know in case of any queries.

Create % overlap matrix in R

I want to take a set of observations & find out how much overlap different columns have based on the indicators. I have the following data:
uniquevalue | X | Y | Z |
Obs 1 | 1 | 0 | 1 |
Obs 2 | 1 | 1 | 0 |
Obs 3 | 1 | 0 | 1 |
Obs 4 | 0 | 1 | 0 |
Obs 5 | 0 | 0 | 1 |
Obs 6 | 0 | 1 | 0 |
Obs 7 | 0 | 0 | 1 |
I want to create the following data overlap matrix:
Label | X | Y | Z |
X | 100% | 33% | 50% |
Y | 33% | 100% | 0% |
Z | 66% | 0% | 100% |
So, for example, Z has a total of 4 observations. 2 of its 4 observations are also present on X, so its overlap % is 50%. However because different columns have different numbers of observations, the reverse is not necessarily true. As you can see, 2 of 3 observations in X are shared with Z, so its a 66% overlap.
You can use crossprod:
mat <- crossprod(as.matrix(df[2:4])) # calculate the overlap
floor(t(mat * 100 / diag(mat))) # calculate the percentage
# X Y Z
#X 100 33 50
#Y 33 100 0
#Z 66 0 100

Convert -WebKit-Filter hue into RGB

The -webkit-filter in CSS3 allows you to apply a hue filter by passing a degree value between 0-360
example:
-webkit-filter: hue-rotate(80deg);
How would you convert the degree value into an RGB value?
The CSS filter hue-rotate is not a true hue-rotation, it's an approximation in RGB space, and is not very accurate for saturated colors. If you want to duplicate what it's doing you need to use the same algorithm - which is not the standard HSL/RGB conversion. Its underlying algorithm is in the SVG 1.1 filter spec for feColorMatrix
For type="hueRotate", ‘values’ is a single one real number value (degrees). A hueRotate operation is equivalent to the following matrix operation:
| R' | | a00 a01 a02 0 0 | | R |
| G' | | a10 a11 a12 0 0 | | G |
| B' | = | a20 a21 a22 0 0 | * | B |
| A' | | 0 0 0 1 0 | | A |
| 1 | | 0 0 0 0 1 | | 1 |
where the terms a00, a01, etc. are calculated as follows:
| a00 a01 a02 | [+0.213 +0.715 +0.072]
| a10 a11 a12 | = [+0.213 +0.715 +0.072] +
| a20 a21 a22 | [+0.213 +0.715 +0.072]
[+0.787 -0.715 -0.072]
cos(hueRotate value) * [-0.213 +0.285 -0.072] +
[-0.213 -0.715 +0.928]
[-0.213 -0.715+0.928]
sin(hueRotate value) * [+0.143 +0.140-0.283]
[-0.787 +0.715+0.072]

How to view a table of tables in Qt?

I using Qt library. And I need to show a table of tables, and sort data in each sub-table.
For examlple something like this (2x2 table of 3x3 tables)
sub 1 | sub 2
-------------------------
| i | 0 | 0 | c | 0 | 0 | s
------------------------- u
| j | 0 | 0 | d | 0 | 0 | b
------------------------- 1
| k | 0 | 0 | e | 0 | 0 |
-------------------------------
| a | 0 | 0 | c | 0 | 0 |
------------------------- s
| b | 0 | 0 | d | 0 | 0 | u
------------------------- b
| c | 0 | 0 | e | 0 | 0 | 2
-------------------------
Any solutions are welcome.
ps. My idea is to implement a custom model with 2d array of models.
You can nest QTableView instances through use of the QAbstractItemView::setIndexWidget method. The data structure you use to maintain the QAbstractTableModel instances is inconsequential as long as each QTableView is assigned an appropriate model instance.

Resources