BSNS102 Study Guide - Final Guide: Stadler Flirt, Eval, Computational Geometry

8 views4 pages

Document Summary

// normalize the vector void normalize() { float magsq = x*x + y*y + z*z; if (magsq > 0. 0f) { // check for divide-by-zero float oneovermag = 1. 0f / sqrt(magsq); x *= oneovermag; y *= oneovermag; z *= oneovermag; // multiplication symbol to do this float operator *(const vector3 &a) const { return x*a. x + y*a. y + z*a. z; // compute the magnitude of a vector inline float vectormag(const vector3 &a) { return sqrt(a. x*a. x + a. y*a. y + a. z*a. z); // compute the cross product of two vectors inline vector3 crossproduct(const vector3 &a, const vector3 &b) { return vector3( a. y*b. z a. z*b. y, a. z*b. x a. x*b. z, a. x*b. y a. y*b. x. // scalar on the left multiplication, for symmetry inline vector3 operator *(float k, const vector3 &v) { return vector3(k*v. x, k*v. y, k*v. z); // we provide a global zero vector constant extern const vector3 kzerovector; Every person who writes code does it slightly different.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers