-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
152 lines (122 loc) · 4.58 KB
/
index.html
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Spherical Coordinate converter</title>
<style>
body{
text-align: center;
}
p{
font-weight:400;
}
fieldset {
width: 1000px;
margin: auto;
padding: 10px;
}
form{
padding:10px;
}
label{
padding-left: 10px;
}
legend{
margin:auto;
}
</style>
</head>
<body>
<h1>Spherical Vector Converter</h1>
<p>Enter Spherical Vector</p>
<form name="spherical" onsubmit="return false">
<label for="Ar">A<sub>r</sub>:</label>
<input type="number" id="Ar" step="any">
<label for="Atheta"><span> A<sub>θ</sub></span></label>
<input type="number" id="Atheta"step="any">
<label for="Aphi"><span> A<sub>ɸ</sub>;</span></label>
<input type="number" id="Aphi"step="any">
</form>
<p>Enter Spherical Coordinates</p>
<form name="spherical_coord" onsubmit="return false">
<label for="x">r:</label>
<input type="number" id="r" step="any">
<label for="y"><span> θ</span></label>
<input type="number" id="theta"step="any">
<label for="z"><span> ɸ</span></label>
<input type="number" id="phi"step="any">
<br><br>
<input type="submit" onclick="convert()">
</form>
<form name="cylindrical" >
<fieldset>
<legend>Cylindrical Vector</legend>
<label for="cyl_r">Ar:</label>
<input type="number" id="cyl_r" value="" readonly>
<label for="cyl_phy"><span> Aɸ</span></label>
<input type="number" id="cyl_phy" readonly>
<label for="cyl_z"><span> Az</span></label>
<input type="number" id="cyl_z" readonly>
</fieldset>
</form>
<form name="cartesan" >
<fieldset>
<legend>Cartesan Vector</legend>
<label for="Ax">Ax</label>
<input type="number" id="Ax"readonly>
<label for="Ay"><span> Ay </span></label>
<input type="number" id="Ay" readonly>
<label for="Az"><span> Az</span></label>
<input type="number" id="Az" readonly>
</fieldset>
</form>
<script>
function convert(){
let Ar = document.forms["spherical"]["Ar"].value;
let Aphi = document.forms["spherical"]["Aphi"].value;
let Atheta = document.forms["spherical"]["Atheta"].value;
let r = document.forms["spherical_coord"]["r"].value
let theta = document.forms["spherical_coord"]["theta"].value
let phi = document.forms["spherical_coord"]["phi"].value
theta = (theta*Math.PI)/180
phi = (phi*Math.PI)/180
console.log(theta,phi)
const xyz = [0,0,0]
const sph = [Ar,Atheta,Aphi]
const cyl = [0,0,0]
const sin_phy = Math.sin(phi)
const cos_phy = Math.cos(phi)
const sin_theta = Math.sin(theta)
const cos_theta = Math.cos(theta)
const sph_xyz = [[(sin_theta*cos_phy),(cos_theta*cos_phy),(-sin_phy)],
[(sin_theta*sin_phy),(cos_theta*sin_phy),cos_phy],
[cos_theta,-sin_theta,0]]
const sph_cyl = [[sin_theta,cos_theta,0],
[0,0,1],[cos_theta,-sin_theta,0]]
multiply(sph_xyz,sph,xyz)
multiply(sph_cyl,sph,cyl)
console.log(sph_xyz)
console.log(xyz)
document.forms["cartesan"]["Ax"].value = xyz[0]
document.forms["cartesan"]["Ay"].value = xyz[1]
document.forms["cartesan"]["Az"].value = xyz[2]
document.forms["cylindrical"]["cyl_r"].value = cyl[0]
document.forms["cylindrical"]["cyl_phy"].value = cyl[1]
document.forms["cylindrical"]["cyl_z"].value = cyl[2]
alert("NEVER\nGONNA\nGIVE\nYOU\nUP\nNEVER\nGONNA\nLET\nYOU\nDOWN\nNEVER\nGONNA\nTURN\nAROUND\nAND\nDESERT\nYOU");
}
function multiply(mat1, mat2, res)
{
let i, j, k;
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
res[i] = 0;
for (k = 0; k < 3; k++)
res[i] += mat1[i][k] * mat2[k];
}
}
}
</script>
</body>
</html>