-
Notifications
You must be signed in to change notification settings - Fork 3
/
turtle-oblique-throw.html
88 lines (79 loc) · 2.38 KB
/
turtle-oblique-throw.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Turtle Blank</title>
<style>
html {
font-family: 'Courier New', Courier, monospace;
}
</style>
</head>
<body>
<script type="text/javascript" src="./js/1px-fix.js"></script>
<script type="text/javascript" src="./js/turtle.js"></script>
<script type="text/javascript">
//init turtle
let t = new Turtle({ debug: false, animate: 1 })
function lineOfTowPoint(x1, y1, x2, y2) {
let k = (y2 - y1) / (x2 - x1)
let b = y1 - k * x1
return { k, b }
}
function title() {
document.write(' Sky draw system [obliqueThrow] <br>')
document.write(' s0 = v0*t, v1 = g*t s1 = v1*t<br>')
document.write(' y = kx + b => x = -b/k | (y=0)<br>')
document.write(' v = 90 m/s<br>')
document.write(' g = 9.8 m/s²<br>')
document.write(' F(air) = 1/2*C*ρ*SV² N<br>')
}
function drawAxis() {
t.setxy(-250, 0).move(250, 0).setxy(0, 250).move(0, -250).home().go()
}
function obliqueThrow(ang = Math.PI / 4, v = 90, g = 9.8, dx = -200) {
let v0 = v * Math.cos(ang)
let v1 = v * Math.sin(ang)
let air = 2
t.home().color('#ff0000')
for (let time = 0; time < 10; time += 0.1) {
const vAir = time => v1 - air * time
const y = time => vAir(time) * time - g * time ** 2
if (y(time) < 0) {
const { k, b } = lineOfTowPoint(
(time - 1) * v0 + dx,
y(time - 1),
time * v0 + dx,
y(time)
)
t.move(-b / k, 0)
break
}
t.move(time * v0 + dx, y(time))
}
t.go()
t.home().color('#000000')
for (let time = 0; time < 10; time += 0.1) {
const y = time => v1 * time - g * time ** 2
if (y(time) < 0) {
const { k, b } = lineOfTowPoint(
(time - 1) * v0 + dx,
y(time - 1),
time * v0 + dx,
y(time)
)
t.move(-b / k, 0)
break
}
t.move(time * v0 + dx, y(time))
}
t.go()
}
title()
drawAxis()
for (let m = 3; m < 7; m += 1) {
obliqueThrow(Math.PI / m)
}
</script>
</body>
</html>