@@ -38,7 +38,7 @@ type VectorTwo = Vector2 Scalar
3838The magnitude of the vector is it's length. We can calculate this using
3939Pythagorean theorem:
4040\begin {equation }
41- x^2 + y^2 = mag ^2
41+ x^2 + y^2 = magnitude ^2
4242\end {equation }
4343
4444In haskell this would be:
@@ -74,11 +74,15 @@ hundreds of vectors so it would be useful to add, for instance a list of
7474vectors together and get one final vector as a result. We can use \textit {foldr }
7575using the zero vector as a starting value.
7676to acomplish this.
77+
78+ \begin {spec}
79+ zeroVector :: VectorTwo
80+ zeroVector = V2 0 0
81+ \end {spec}
82+
7783\begin {code}
7884addListOfVectors :: [VectorTwo ] -> VectorTwo
7985addListOfVectors = foldr add zeroVector
80- where
81- zeroVector = V2 0 0
8286\end {code}
8387
8488Let's try it out!
@@ -100,15 +104,15 @@ coordinates let's make our own instance for Show.
100104
101105\begin {code}
102106instance Show num => Show (Vector2 num ) where
103- show (V2 x y) = " (" ++ show x ++ " x , " ++ show y ++ " y )"
107+ show (V2 x y) = " (" ++ show x ++ " , " ++ show y ++ " )"
104108\end {code}
105109
106110And let's try our example again:
107111`` `
108112 *Vector> let vec1 = V2 5 3
109113 *Vector> let vec2 = V2 6 5
110- *Vector> sub2 vec1 vec2
111- (-1.0 x, -1.0 y)
114+ *Vector> sub vec1 vec2
115+ (-1 x, -2 y)
112116`` `
113117
114118And let's also try adding a list of vectors using our new function:
@@ -117,7 +121,7 @@ And let's also try adding a list of vectors using our new function:
117121 *Vector> let vec3 = V2 8 9
118122 *Vector> let vectors = [vec1, vec2, vec3]
119123 *Vector> addListOfVectors vectors
120- (19.0 x, 18 .0 y)
124+ (19.0 x, 17 .0 y)
121125`` `
122126
123127It works!
@@ -208,7 +212,7 @@ direction of $y$ will be boosted. But there are worse ways to hit the dash
208212panel. We could for instance create a new velocity vector with the exact same
209213magnitude of speed but which would recieve a worse boost.
210214
211- % TODO: Picture of mario kart / dash panel
215+ {.float-img-right}
212216
213217\begin {code}
214218worseCart :: VectorTwo
228232We talked a lot about angles between vectors but we havn't used it in our code,
229233so lets make a function which calculates the angle of a vector. The formula is
230234as follows:
231- % TODO
232- \textbf { Insert picture of angle of triangle here }
235+
236+ {.float-img-center}
233237
234238We'll use Doubles to represent the angle.
235239\begin {code}
@@ -239,7 +243,7 @@ angle :: VectorTwo -> Scalar
239243angle (V2 x y) = atan y/ x
240244\end {code}
241245
242- Using angles and magnitudes we can even make a new function for making vectors:
246+ Using angles and magnitudes we can even write a new function for making vectors:
243247
244248\begin {code}
245249mkVector :: Scalar -> Angle -> VectorTwo
@@ -249,10 +253,6 @@ mkVector mag angle = V2 x y
249253 y = mag * sin angle
250254\end {code}
251255
252- % -- Angle between two vectors
253- % angleG :: Vector vec => vec -> vec -> Scalar
254- % angleG v1 v2 = (dotProd v1 v2) / ((magnitude v1) * (magnitude v2))
255-
256256Vectors in three dimensions.
257257--------------------------------------
258258
@@ -344,10 +344,10 @@ between vectors.
344344\begin {code}
345345add :: (Num num , Vector vec ) => vec num -> vec num -> vec num
346346add = vzipWith (+)
347- \end {code}
348347
349348sub :: (Num num , Vector vec ) => vec num -> vec num -> vec num
350349sub = vzipWith (-)
350+ \end {code}
351351
352352For multiplying with a scalar:
353353
0 commit comments