isParallelTo method
Checks if this Vector is parallel to other.
Two vectors are parallel if their cross product has a magnitude of 0.
Example:
var vector1 = Vector(1, 0, 0);
var vector2 = Vector(2, 0, 0);
print(vector1.isParallelTo(vector2)); // Output: true
Returns true if the vectors are parallel, and false otherwise.
Implementation
bool isParallelTo(Vector other) {
if (length != 3 || other.length != 3) {
throw ArgumentError("Both vectors must be three-dimensional.");
}
if (magnitude == 0 || other.magnitude == 0) {
throw ArgumentError(
'Neither the Vector nor the other Vector can be zero');
}
// Two vectors are parallel if their cross product has a magnitude of 0.
return cross(other).magnitude < 1e-10;
}