Vec2 is a two-dimensional vector class in C++ language used to represent coordinates in 2D space. It encapsulates two floating-point values, x and y, which can be used to represent position or direction.

**Example 1:** Creating a Vec2 object and accessing its components.

This example shows how to create a Vec2 object with initial values of x=1.0f and y=2.0f and how to access its components using the dot notation.

**Example 2:** Vector arithmetic operations.

#include#include "Vec2.h" int main() { Vec2 position(1.0f, 2.0f); std::cout << "Position x=" << position.x << ", y=" << position.y << std::endl; return 0; }

This example shows how to create a Vec2 object with initial values of x=1.0f and y=2.0f and how to access its components using the dot notation.

#includeThis example shows how to perform vector arithmetic operations such as addition, multiplication, and finding the length of the vector using the length() method. This example also shows the use of operator overloading to perform vector operations. Vec2 belongs to the package or library called MathGeoLib, which provides various mathematics operations related to geometry, linear algebra, and physics.#include "Vec2.h" int main() { Vec2 position(1.0f, 2.0f); Vec2 velocity(3.0f, 4.0f); Vec2 acceleration(0.1f, 0.2f); position += velocity; velocity += acceleration; position *= 2.0f; std::cout << "Position x=" << position.x << ", y=" << position.y << std::endl; std::cout << "Velocity x=" << velocity.x << ", y=" << velocity.y << std::endl; float distance = velocity.length(); std::cout << "Distance=" << distance << std::endl; return 0; }

Frequently Used Methods

Frequently Used Methods

Frequently Used Methods

Related in langs

Frequently Used Methods

Related