Can anyone help me (again) please? I have a Matrix like this:
1.0 0.0 0.0 2.5
0.0 1.0 0.0 0.0
0.0 0.0 1.0 0.0
0.0 0.0 0.0 1.0
How can I rotate it 20° in X axis, -128° in Y axis and 72.1° in Z axis simultaneously?
thank you very much
I want rotate … in X axis, … in Y axis and … in Z axis simultaneously
You can't. What you ask for is mathematically undefined. There are 6 permutations of the order in which the elementary rotations could be combined…
X Y Z
X Z Y
Y X Z
Y Z X
Z X Y
Z Y X
and each of them has a different result. Rotations don't work the way you think. Mathematically rotations in 3 dimensional space form a special unitary group of degree 2, also written as SU(2). Each rotation in SU(2) is unique but can be constructed by combining an infinite number of other rotations in SU(2).
In your particular case there's no particular solution to the problem. The best thing you can do is choose a particular execution order and apply the rotations one after another onto your existing coordinate system, by forming the corresponding rotation matrix and multiplying onto the matrix representing the previous coordinate system/transformation step.
Related
I need some help with programming the calculation of displacement. Given the distance the object has moved in the XY plane, and the yaw (heading) of the object, I'd like to calculate the displacement of the object. For example, the object moved 5m North and 2m East.
The data I have is the distance it travels in the XY plane (X distance and Y distance) and the heading of the device which is determined by the direction of X. I know how to calculate it on paper but I am having trouble to program it.
I've attached two examples that shows how I obtained the calculations. The black dot is the displacement of the object. In the 1st example, the X-distance travelled is 3 meters while the Y-distance is 4 meters and the heading of the X-axis is 70°. After calculating, I managed to get that it has travelled 2.733m South and 4.187m East. In example 2, it travel, the X-distance is -5m and the Y-distance is -12m, the heading is 160°. I calculated that the object travels 8.80m North and 9.566m East.
Example 1
Example 2
Assume you have your XY pane rotated by some angle Zp and have a 2D movement vector within that pane, let's say its direction rotated by Zv – what is total rotation of the vector, relative to the global orientation? Zp + Zv...
So all you need to do is applying the rotation Zp to the movement vector within XY-pane, i. e. apply a rotation matrix to the vector. This matrix for a rotation by z looks like:
cos(z) -sin(z)
sin(z) cos(z)
With our data above:
north = cos(Zp) * x - sin(Zp) * y
east = sin(Zp) * x + cos(Zp) * y
which gives, with your first sample data applied:
north = cos(70°) * 3 - sin(70°) * 4 ~ -2.7327
east = sin(70°) * 3 + cos(70°) * 4 ~ 4.1872
north = cos(160°) * -5 - sin(160°) * -12 ~ 8.8027
east = sin(160°) * -5 + cos(160°) * -12 ~ 9.5662
Corresponding pretty much to the values you calculated (note: negative movement to north is positive movement towards south...).
What you are doing is a conversion from polar to Cartesian coordinates. https://en.wikipedia.org/wiki/Polar_coordinate_system#Converting_between_polar_and_Cartesian_coordinates
If your Cartesian coordinates are not aligned to the polar axis, just compensate by adding the rotation angle to the polar argument.
this is my first post ever here so I'm not quit sure what is the proper form to ask the question. I'm trying to put picture of the results but since its my first post, the website telling me that I need 10 positive post for some credibility so I think that my charts doesn't appear. Also, I'm french, not perfectly bilingual. Please, be indulgent, I'm open for all comments and suggestions. I really need this for my master's projet. Thank you very much!
I have two sets of arrays which contains thousands of values In one (x_1_3) is all the value of temperature and y_0_100 contain only 0's and 100's which are associated to every temperature in x_1_3 sorted.
x_1_3 = array([[ 2.02],
[ 2.01],
[ 3.08],
...,
[ 0.16],
[ 0.17],
[-2.12]])
y_0_100 = array([ 0., 0., 0., ..., 100., 100., 100.])
The 0 in y_0_100 represent solid precipitation and 100 represent liquid precipitation I just want to plot a logistic regression line across my values
(I also tried to put the values in a dataframe, but it didnt work)
dfsnow_rain
AirTemp liquid%
0 2.02 0.0
1 2.01 0.0
2 3.08 0.0
3 3.05 0.0
4 4.89 0.0
... ... ...
7526 0.78 100.0
7527 0.40 100.0
7528 0.16 100.0
7529 0.17 100.0
7530 -2.12 100.0
7531 rows × 2 columns
X = x_1_3
y = y_0_100
# Fit the classifier
clf = linear_model.LogisticRegression(C=1e5)
clf.fit(X, y)
# and plot the result
plt.figure(1, figsize=(10, 5))
plt.clf()
plt.scatter(X.ravel(), y, color='black', zorder=20)
X_test = np.linspace(-15, 15, 300)
loss = expit(X_test * clf.coef_ + clf.intercept_).ravel()
plt.plot(X_test, loss, color='red', linewidth=3)
ols = linear_model.LinearRegression()
ols.fit(X, y)
plt.plot(X_test, ols.coef_ * X_test + ols.intercept_, linewidth=1)
#plt.axhline(1, color='.5')
plt.ylabel('y')
plt.xlabel('X')
plt.xticks(range(-10, 10))
plt.yticks([0, 100, 10])
plt.ylim(0, 100)
plt.xlim(-10, 10)
plt.legend(('Logistic Regression Model', 'Linear Regression Model'),
loc="lower right", fontsize='small')
plt.tight_layout()
plt.show()
Chart results
When I zoom in I realise that my logistic regression line is not flat, its the line that curves in a very small range (see picture below)
Chart when it's zoomed
I would like something more like this :
Logistic regression chart i would like
What am i doing wrong here? I just want to plot a regression line across my values from y0 to y100
I know that a Hadamard gate is implemented by rotating around the axis (x + z )/ sqrt(2), but how can I compute the matrix obtained by rotation around this axis by π radians, and compare to a Hadamard gate matrix.
Thanks for your help.
Using H = (x + z)/ sqrt(2)
Find the rotation along x-axis (rx), and rotation along z-axis (rz), then multiply.
I have 2 lists of x and y coordinate that are independently generated, with a/h amount of points between 0 and a.
x = np.linspace(0, a, a/h)
y = np.linspace(0, d, d/h)
when a/h is such that 0 increases to a in steps of integers i.e. [0,1,2,..,a]. It's nice because then the number of elements within the list can be used as indices. And as a result I can usually create a meshgrid such that a third list V1 can be associated with it.
X, Y = plt.meshgrid(x, y)
def potential(V1):
return V1[X, Y]
where potential(V1) is now V1 corresponding to the meshgrid [x, y]. However I'm doing an assignment where I'm required to investigate how step-sizes affect my problem. As a result if I was to have a step-size of non-integers from 0 to a i.e. [0, 0.5, 1,...,a] Now I can't do what I did above since the indices are now non-integers. Raising the error
IndexError: arrays used as indices must be of integer (or boolean) type
How can I fix this so that I don't rely on the value of the element itself as the index of the elements, so that if there was a step-size of 0.25 between 0 to a for a list X say i.e.
X = [0, 0.25, 0.75. 1.0] or x = np.linspace(0,1,4)
such that I can have
x[0] = 0 corresponds to V[0]
x[1] = 0.25 corresponds to V[1]
x[2] = 0.75 corresponds to V[2]
x[3] = 1 corresponds to V[3]
?
I've got a question about forming the loop function for processing the earthquake data per bin.
Our map is as below, with the data, and runs from -125W to -114W, and 32N to 42N.
In order to process the data quickly and efficiently, we should use a loop. However, I'm not sure how to go about starting it!
We would like to sample a 1x1 degree bin, roughly as below...
Starting in the top left corner, sample 41 to 42N and -125 to -124W
Run calculation on sample area
Move 1 degree East and run calculation
repeat until at rightmost edge
return to leftmost edge and move down a degree.
Could anyone advise on how to do this? I'm not sure where to start, so if someone can outline a framework from which I can adapt... :)
Once we have worked out how to do it for a 1 degree bin, we can improve resolution and run our calculations :)
The code below nests the loops as required
printf "" >! loop1.txt
# x = -125
while ($x <= -114)
# y = 32
while ($y <= 42)
printf "$x $y\n" >> loop1.txt
# y++
end
# x++
end2
and produces an output of
x1 y1
x1 y2
x1 y3
x2 y1
x2 y2
x2 y3
etc.
Required now, however, is to integrate an awk command during the second loop, to create a third column output