Vector
Depending on the context, a vector can refer to three different concepts:
- In mathematics, a vector is a quantity with both magnitude and direction.
- In computer graphics, vectors define shapes and paths that can be scaled without losing quality.
- In computer science, a vector is a dynamic data structure that can grow or shrink as needed.
1. Mathematical Vectors
A mathematical vector is a quantity defined by two values:
- magnitude (length)
- direction (angle)
It can be represented visually as an arrow, where the length of the arrow is the magnitude, and the way it points is the direction. For example, one vector may be illustrated by a 2-centimeter arrow pointing at 45 degrees, while another might be 4 centimeters long and point at 30 degrees. Vectors are commonly used in physics, engineering, and other fields to represent movement, force, and velocity.
2. Vectors in Computer Graphics
In computer graphics, a vector graphic is an image comprised of points, lines, and curves defined by mathematical formulas. Unlike raster graphics, which store image data as pixels, vector images can be scaled to any size without becoming blurry or pixelated. Common file formats that use vector graphics include .SVG, .EPS, and .AI (Adobe Illustrator) files.
3. Vectors in Computer Science
In computer science, a vector refers to a dynamic array — a data structure used to store a sequence of values. Unlike a regular array, which has a fixed size, a vector can automatically expand or shrink as elements are added or removed. Vectors manage memory dynamically. They typically use a heap instead of the stack, giving them greater flexibility.
Many programming languages, such as C++ and Java, include built-in vector classes that automatically handle memory allocation and resizing.