Expand description
A 2D vector.
This can be interpreted as a point in 2-space, a translation, a vector, or a complex number; the interpretation is not indicated in the type.
Fields§
§x: f64
§y: f64
Implementations§
source§impl Vec2
impl Vec2
sourcepub fn cross(&self, other: Vec2) -> f64
pub fn cross(&self, other: Vec2) -> f64
Cross product of two vectors.
This is signed so that (0, 1) × (1, 0) = 1.
sourcepub fn atan2(&self) -> f64
pub fn atan2(&self) -> f64
Angle of vector.
If the vector is interpreted as a complex number, this is the argument.
sourcepub fn from_angle(th: f64) -> Vec2
pub fn from_angle(th: f64) -> Vec2
A unit vector of the given angle.
With th
at zero, the result is the positive X unit vector, and
at π/2, it is the positive Y unit vector.
Thus, in a Y-down coordinate system (as is common for graphics),
it is a clockwise rotation, and in Y-up (traditional for math), it
is anti-clockwise. This convention is consistent with
Affine::rotate
.
Trait Implementations§
source§impl AddAssign<Vec2> for Vec2
impl AddAssign<Vec2> for Vec2
source§fn add_assign(&mut self, other: Vec2)
fn add_assign(&mut self, other: Vec2)
Performs the
+=
operation. Read moresource§impl DivAssign<f64> for Vec2
impl DivAssign<f64> for Vec2
source§fn div_assign(&mut self, other: f64)
fn div_assign(&mut self, other: f64)
Performs the
/=
operation. Read moresource§impl MulAssign<f64> for Vec2
impl MulAssign<f64> for Vec2
source§fn mul_assign(&mut self, other: f64)
fn mul_assign(&mut self, other: f64)
Performs the
*=
operation. Read moresource§impl SubAssign<Vec2> for Vec2
impl SubAssign<Vec2> for Vec2
source§fn sub_assign(&mut self, other: Vec2)
fn sub_assign(&mut self, other: Vec2)
Performs the
-=
operation. Read more