Professional Documents
Culture Documents
Finding Angle Between Vectors Using Python and C PDF
Finding Angle Between Vectors Using Python and C PDF
PYTHON TO C
P.Srijith Reddy
EE19BTECH11041
IIT Hyderabad
1 / 17
Outline
1 Problem
2 Solution
Finding angle between A and B.
3 solution
proof for expansion of A×(B × C )
4 code in python
5 Plot
2 / 17
Problem
Problem Statement
3 / 17
Solution Finding angle between A and B.
4 / 17
solution proof for expansion of A×(B × C )
PROOF
Let
ax
A = ay i j k (4.1)
az
bx
B = by i j k
(4.2)
bz
cx
C = cy i j k (4.3)
cz
Now
i j k
B × C = bx
by bz (4.4)
cx cy cz
Now
i j k
A × (B × C) = ax ay az (4.6)
by cz − bz cy −(bx cz − bz cx ) bx cy − by cx
6 / 17
solution proof for expansion of A×(B × C )
7 / 17
solution proof for expansion of A×(B × C )
therefore √
T 3
(A B + )C × B = 0 (4.12)
2
Either √
T 3
(A B + )=0 (4.13)
2
or
C×B=0 (4.14)
But since it is given that B is not parallel to C,
C × B 6= 0 (4.15)
So, √
T 3
(A B + )=0 (4.16)
2
implies √
T 3
A B=− (4.17)
2
8 / 17
solution proof for expansion of A×(B × C )
AT B = kAkkBkCOS(θ1 ) (4.18)
where θ1 is angle between A and B. Since,
9 / 17
solution proof for expansion of A×(B × C )
AT C = kAkkCkCOS(θ2 ) (4.23)
where θ2 is angle between A and C. Since,
10 / 17
code in python
code in python
11 / 17
code in python
code in python
12 / 17
code in python
code in python
ax.scatter(O[0],O[1],O[2],’o’,label=”Point O”)
ax.scatter(A[0],A[1],A[2],’o’,label=”Point A”)
ax.scatter(C[0],C[1],C[2],’o’,label=”Point C”)
ax.scatter(B[0],B[1],B[2],’o’,label=”Point B”)
#ax.plot surface(xx, yy, z, color=’r’,alpha=1)
#plotting line
plt.plot(l1 p[0,:],l1 p[1,:],l1 p[2,:],label=”Line L1”)
plt.plot(l2 p[0,:],l2 p[1,:],l2 p[2,:],label=”Line L2”)
plt.plot(l3 p[0,:],l3 p[1,:],l3 p[2,:],label=”Line L3”)
#show plot
plt.xlabel(’$x$’);plt.ylabel(’$y$’)
plt.legend(loc=’best’);plt.grid()
plt.show()
13 / 17
code in python
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include ”coeffs.h”
int main() //main function begins
{
double∗∗B=createMat(3,1);
B[0][0]=−sqrt(3)/2;B[1][0]=0.5;B[2][0]=0;
printf(”B=\n”);savetxt(B,”B.dat”,3,1);
print(B,3,1);
double∗∗C=createMat(3,1);
C[0][0]=sqrt(3)/2;C[1][0]=0.5;C[2][0]=0;
printf(”C=\n”);savetxt(C,”C.dat”,3,1);
14 / 17
code in python
15 / 17
code in python
Now we are going to plot one set of vectors satisfying given condition and
1
A = 0 (5.1)
0
√
− 3/2
B = 1/2 (5.2)
0
√
3/2
C = 1/2 (5.3)
0
satisfy the given condition.
16 / 17
Plot
Plot
The code in
https://github.com/SRIJITH01/Srijith/blob/master/presentation2.py
plots Fig. 1.
Figure: The above plot is for set of vectors staisfying given condition .
17 / 17