Calculate the dot product between this vector and other. The dot product of two vectors is calculated as so:: Let v1 be a vector such that v1 = Let v2 be a vector such that v2 = v1 . v2 = v1_x * v2_
(self, other)
| 247 | return "<{}, {}>".format(pretty_x, pretty_y) |
| 248 | |
| 249 | def dot(self, other): |
| 250 | """ |
| 251 | Calculate the dot product between this vector and other. |
| 252 | |
| 253 | The dot product of two vectors is calculated as so:: |
| 254 | |
| 255 | Let v1 be a vector such that v1 = <v1_x, v1_y> |
| 256 | Let v2 be a vector such that v2 = <v2_x, v2_y> |
| 257 | |
| 258 | v1 . v2 = v1_x * v2_x + v1_y * v2_y |
| 259 | |
| 260 | Example: |
| 261 | |
| 262 | .. code-block:: python |
| 263 | |
| 264 | from pygorithm.geometry import vector2 |
| 265 | |
| 266 | vec1 = vector2.Vector2(3, 5) |
| 267 | vec2 = vector2.Vector2(7, 11) |
| 268 | |
| 269 | dot_12 = vec1.dot(vec2) |
| 270 | |
| 271 | # prints 76 |
| 272 | print(dot_12) |
| 273 | |
| 274 | :param other: the other vector |
| 275 | :type other: :class:`pygorithm.geometry.vector2.Vector2` |
| 276 | :returns: the dot product of self and other |
| 277 | :rtype: :class:`numbers.Number` |
| 278 | """ |
| 279 | |
| 280 | return self.x * other.x + self.y * other.y |
| 281 | |
| 282 | def cross(self, other): |
| 283 | """ |
no outgoing calls