Skip to content

Commit cc0573e

Browse files
docs: Vector demos ( Fixes #7 )
1 parent 670954a commit cc0573e

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#1. Getting Vectors
2+
3+
# Numbers are great!
4+
5+
# When we measure things with one number, it's technically called a scalar.
6+
7+
# When we measure things with more than one number, it's called a vector
8+
9+
# We can do lots of things with vectors. We can add or substract them, multiply and divide them.
10+
11+
# Vectors are very useful.
12+
13+
# Let's see how we can get a vector:
14+
15+
# Create a 2D vector
16+
[Numerics.Vector2]::new(1,2)
17+
# Create a 3D vector
18+
[Numerics.Vector3]::new(1,2,3)
19+
# Create a 4D vector
20+
[Numerics.Vector4]::new(1,2,3,4)
21+
22+
23+
# The Vector module gives us three vector commands:
24+
Get-Vector2 1 2
25+
Get-Vector3 1 2 3
26+
Get-Vector4 1 2 3 4
27+
28+
# We can drop the `get`
29+
Vector2 1 2
30+
Vector3 1 2 3
31+
Vector4 1 2 3 4
32+
33+
# We can use the shorthand `v2`, `v3`, `v4`
34+
v2 1 2
35+
v3 1 2 3
36+
v4 1 2 3 4
37+
38+
# We can create vectors from a number
39+
v2 1
40+
v3 1
41+
v4 1
42+
43+
# Strings can be vectors, too (we just get the bytes)
44+
v2 "hi"
45+
v3 "hi"
46+
v4 "hi"
47+
48+
# Let's start with addition.
49+
# We can add a scalar to a vector.
50+
(v2 1 2) + 1
51+
(v3 1 2 3) + 1
52+
(v4 1 2 3 4) + 1
53+
54+
# Let's try substraction:
55+
(v2 1 2) - 1
56+
(v3 1 2 3) - 1
57+
(v4 1 2 3 4) - 1
58+
59+
# How about multiplication?
60+
(v2 1 2) * 2
61+
(v3 1 2 3) * 2
62+
(v4 1 2 3 4) * 2
63+
64+
# What about division?
65+
(v2 1 2) / 2
66+
(v3 1 2 3) / 2
67+
(v4 1 2 3 4) / 2
68+
69+
# We can also work with other vectors:
70+
71+
# Adding vectors:
72+
(v2 1 2) + (v2 1 2)
73+
(v3 1 2 3) + (v3 1 2 3)
74+
(v4 1 2 3 4) + (v4 1 2 3 4)
75+
76+
# Subtracting vectors:
77+
(v2 1 2) - (v2 1 2)
78+
(v3 1 2 3) - (v3 1 2 3)
79+
(v4 1 2 3 4) - (v4 1 2 3 4)
80+
81+
# Multiplying vectors:
82+
(v2 1 2) * (v2 1 2)
83+
(v3 1 2 3) * (v3 1 2 3)
84+
(v4 1 2 3 4) * (v4 1 2 3 4)
85+
86+
# Dividing vectors:
87+
(v2 1 2) / (v2 1 2)
88+
(v3 1 2 3) / (v3 1 2 3)
89+
(v4 1 2 3 4) / (v4 1 2 3 4)
90+
91+
92+
# We can also negate a vector:
93+
-(v2 1 2)
94+
-(v3 1 2 3)
95+
-(v4 1 2 3 4)
96+
97+
# We can compare two vectors to see if they are equal
98+
(v2 1 2) -eq (v2 1 2)
99+
(v3 1 2 3) -eq (v3 1 2 3)
100+
(v4 1 2 3 4) -eq (v4 1 2 3 4)
101+
102+
# We can also see if they are not equal
103+
(v2 1 2) -ne (v2 1 2)
104+
(v3 1 2 3) -ne (v3 1 2 3)
105+
(v4 1 2 3 4) -ne (v4 1 2 3 4)
106+

0 commit comments

Comments
 (0)