SBVEC2F(3iv)

๐Ÿ’– SbVec2f โ€” the 2D vector class (from the 3IV manual, bestie)

okay so picture this: you need to store a 2D vector. a point. a lil (x, y) situation. that's SbVec2f, and she is the moment. she's used all over Inventor for arguments and return values, which honestly makes her the main character of linear algebra in this library. periodt. ๐Ÿ’…


๐ŸŒธ INHERITS FROM

SbVec2f โ€” yeah she inherits from herself, iconic behaviour honestly, no notes โœจ


๐ŸŽ€ SYNOPSIS

first, the incantation to even get her in the room:

#include <Inventor/SbLinear.h>

then, all her methods, verbatim, in all their glory:

                    SbVec2f()
                    SbVec2f(const float v[2])
                    SbVec2f(float x, float y)
float               dot(const SbVec2f &v) const
SbBool              equals(const SbVec2f v, float tolerance) const
const float *       getValue() const
void                getValue(float &x, float &y) const
float               length() const
void                negate()
float               normalize()
SbVec2f &           setValue(const float v[2])
SbVec2f &           setValue(float x, float y)
float &             operator [](int i)
const float &       operator [](int i)
SbVec2f &           operator *=(float d)
SbVec2f &           operator /=(float d)
SbVec2f &           operator +=(const SbVec2f &u)
SbVec2f &           operator -=(const SbVec2f &u)
SbVec2f             operator -() const
SbVec2f             operator *(const SbVec2f &v, float d)
SbVec2f             operator *(float d, const SbVec2f &v)
SbVec2f             operator /(const SbVec2f &v, float d)
SbVec2f             operator +(const SbVec2f &v1, const SbVec2f &v2)
SbVec2f             operator -(const SbVec2f &v1, const SbVec2f &v2)
int                 operator ==(const SbVec2f &v1, const SbVec2f &v2)
int                 operator !=(const SbVec2f &v1, const SbVec2f &v2)

โœจ DESCRIPTION โœจ

so. SbVec2f is the 2D vector class that holds your 2D vectors and points. that's it, that's her whole job, and she does it flawlessly. ๐Ÿฆ‹

she's used throughout Inventor for arguments and return values, so like, you WILL be seeing her again. she's everywhere. she's the vibe.


๐Ÿ’… METHODS ๐Ÿ’…

the constructors ๐Ÿผ

  • SbVec2f() โ€” the default constructor. no args, no drama, just an empty lil vector waiting to be something. ๐Ÿ™ˆ
  • SbVec2f(const float v[2])
  • SbVec2f(float x, float y) โ€” constructor given vector components. hand her your numbers (either a float array of 2, or x and y separately) and she's ready. slay. โœจ

the maths girlies ๐Ÿงฎ

  • float dot(const SbVec2f &v) const โ€” returns the dot (inner) product of your vector and another vector. it's giving "multiply and add, bestie."
  • SbBool equals(const SbVec2f v, float tolerance) const โ€” equality comparison within a given tolerance โ€” and heads up, the tolerance is the square of the length of the maximum distance between the two vectors. yes, the SQUARE. not the distance itself. don't get caught out. ๐Ÿ˜ญ
  • float length() const โ€” returns the geometric length of the vector. how long is she? very. ๐Ÿ‘‘
  • void negate() โ€” negates each component of the vector, in place. she flips herself, no new object, no waste. sustainable queen. ๐ŸŒธ
  • float normalize() โ€” changes the vector to be unit length. she shrinks down to size 1 and stays that way. ๐Ÿ’…

getting and setting ๐Ÿ“

  • const float * getValue() const
  • void getValue(float &x, float &y) const โ€” returns vector components. either you get the pointer, or you get x and y handed to you by reference. both valid, both cute. ๐ŸŽ€
  • SbVec2f & setValue(const float v[2])
  • SbVec2f & setValue(float x, float y) โ€” sets the vector components. feed her the array, or feed her the two floats. she returns herself back so you can chain, which is highkey thoughtful of her. ๐Ÿซถ
  • float & operator [](int i)
  • const float & operator [](int i) โ€” accesses the indexed component of the vector. yes, there's a const version, because she respects const-correctness. โญ

the operator section, aka where she really ate ๐Ÿ”ฅ

  • SbVec2f & operator *=(float d)
  • SbVec2f & operator /=(float d) โ€” component-wise scalar multiplication and division operators. one scalar, applied to everything, in place.
  • SbVec2f & operator +=(const SbVec2f &u)
  • SbVec2f & operator -=(const SbVec2f &u) โ€” component-wise vector addition and subtraction operators. also in place. also returning a reference to herself. also iconic.
  • SbVec2f operator -() const โ€” nondestructive unary negation โ€” returns a new vector. she does NOT touch the original. that's the whole point. do not confuse her with negate(). ๐Ÿ‘€
  • SbVec2f operator *(const SbVec2f &v, float d)
  • SbVec2f operator *(float d, const SbVec2f &v)
  • SbVec2f operator /(const SbVec2f &v, float d) โ€” component-wise binary scalar multiplication and division operators. note there's a version with the scalar on the left AND one with it on the right, because she plays both sides. generous. โœจ
  • SbVec2f operator +(const SbVec2f &v1, const SbVec2f &v2)
  • SbVec2f operator -(const SbVec2f &v1, const SbVec2f &v2) โ€” component-wise binary vector addition and subtraction operators.
  • int operator ==(const SbVec2f &v1, const SbVec2f &v2)
  • int operator !=(const SbVec2f &v1, const SbVec2f &v2) โ€” equality comparison operators. they hand you back an int, and you just accept that. ๐Ÿ˜Œ

๐ŸŒˆ SEE ALSO

if you liked her, you'll love her friends:

  • SbVec3f
  • SbVec4f
  • SbVec2s
  • SbRotation

ngl bestie, if you remember nothing else, remember: negate() mutates, unary operator -() doesn't, and the equals tolerance is the SQUARE of that max distance. that's the whole vibe check. ๐Ÿงš

and that's the page!! this was SbVec2f(3IV), from the 3IV manual, dated and versioned exactly as she always was โ€” no cap, same source, same date, just delivered with a little more ๐Ÿ’– than usual. mwah. ๐ŸŽ€๐Ÿ’œ