Added cross-product to vector implementation

This commit is contained in:
Martin Opat 2024-12-23 22:01:09 +01:00
parent 94e82787e1
commit a1c6ab16ab
1 changed files with 1 additions and 0 deletions

View File

@ -14,5 +14,6 @@ struct Vec3 { // TODO: Maybe make this into a class
__host__ __device__ Vec3 operator*(double b) const { return Vec3(x * b, y * b, z * b); } __host__ __device__ Vec3 operator*(double b) const { return Vec3(x * b, y * b, z * b); }
__host__ __device__ Vec3 operator-() const { return Vec3(-x, -y, -z); } __host__ __device__ Vec3 operator-() const { return Vec3(-x, -y, -z); }
__host__ __device__ double dot(const Vec3& b) const { return x * b.x + y * b.y + z * b.z; } __host__ __device__ double dot(const Vec3& b) const { return x * b.x + y * b.y + z * b.z; }
__host__ __device__ Vec3 cross(const Vec3& b) const { return Vec3(y * b.z - z * b.y, z * b.x - x * b.z, x * b.y - y * b.x); }
__host__ __device__ Vec3 normalize() const { double len = sqrt(x * x + y * y + z * z); return Vec3(x / len, y / len, z / len); } __host__ __device__ Vec3 normalize() const { double len = sqrt(x * x + y * y + z * z); return Vec3(x / len, y / len, z / len); }
}; };