A C++ console application for performing 2D and 3D vector operations with interactive menus and Gnuplot visualization.
- Vector Addition — Add two 2D or 3D vectors
- Vector Subtraction — Subtract two 2D or 3D vectors
- Scalar Multiplication — Multiply a vector by a scalar
- Dot Product — Compute the scalar dot product of two vectors
- Cross Product — Compute the cross product of two 3D vectors
- Magnitude — Compute the length/magnitude of a vector
- Angle Between Vectors — Compute the angle in degrees between two vectors
- Plot Two Vectors — Visualize two vectors and their resultant using Gnuplot (normalized)
VectorCalculator/
├── main.cpp # Entry point, menu, input handling, operation dispatch
├── vector.hpp # Vector2D and Vector3D class declarations
├── vector.cpp # Vector2D and Vector3D method implementations
└── gnuplot-iostream.h # Gnuplot C++ interface header
| Dependency | Purpose |
|---|---|
| Gnuplot | Plotting vectors visually |
| Boost | boost::tuple used for Gnuplot data formatting |
| Windows SDK | Console handling (Windows.h, conio.h) |
Note: This project currently targets Windows only due to the use of
Windows.handconio.h.
Download and install Gnuplot from gnuplot.info.
The default path expected by the application is:
C:\Program Files\gnuplot\bin\gnuplot.exe
If your installation path differs, update this line in main.cpp:
Gnuplot gp("\"C:\\Program Files\\gnuplot\\bin\\gnuplot.exe\"");Download Boost from boost.org and add the include path to your compiler/IDE settings.
Using g++ (MinGW on Windows):
g++ main.cpp vector.cpp -o VectorCalculator -I path/to/boostOr open the project in Visual Studio and build normally after configuring Boost include paths.
Run the executable. You will see the following menu:
----SIMPLE VECTOR CALCULATOR----
1. Vector Addition
2. Vector Subtraction
3. Vector Multiplication
4. Dot Product
5. Cross Product (3D only)
6. Magnitude
7. Angle Between Vectors
8. Plot Two Vectors
0. Exit
- 2D vector: Enter two space-separated numbers
Enter the First vector: 3 4 - 3D vector: Enter three space-separated numbers
Enter the First vector: 1 2 3
The application automatically detects whether input is 2D or 3D based on the number of components provided.
Option: 4
Enter the First vector: 1 2 3
Enter the Second vector: 4 5 6
Resultant Scalar: [32]
Option: 5
Enter the First vector: 1 0 0
Enter the Second vector: 0 1 0
Resultant Vector: [0, 0, 1]
Selecting Plot opens a Gnuplot window displaying both vectors and their resultant, all normalized to unit length for consistent visualization.
| Operation | 2D | 3D |
|---|---|---|
| Addition | ✅ | ✅ |
| Subtraction | ✅ | ✅ |
| Scalar Multiplication | ✅ | ✅ |
| Dot Product | ✅ | ✅ |
| Cross Product | ❌ | ✅ |
| Magnitude | ✅ | ✅ |
| Angle Between | ✅ | ✅ |
| Plot | ✅ | ✅ |
Cross product is only defined for 3D vectors. Attempting it with 2D vectors will return an error.
Vector2D(double x, double y);
Vector2D operator+(const Vector2D& other) const;
Vector2D operator-(const Vector2D& other) const;
Vector2D operator*(double scalar) const;
double dotProduct(const Vector2D& other) const;
double magnitude() const;
double angleBetween(const Vector2D& other) const; // returns degrees
Vector2D normalize() const;Vector3D(double x, double y, double z);
Vector3D operator+(const Vector3D& other) const;
Vector3D operator-(const Vector3D& other) const;
Vector3D operator*(double scalar) const;
double dotProduct(const Vector3D& other) const;
Vector3D crossProduct(const Vector3D& other) const;
double magnitude() const;
double angleBetween(const Vector3D& other) const; // returns degrees
Vector3D normalize() const;- Windows only (uses
Windows.handconio.h) - Gnuplot path is hardcoded — update manually if installed elsewhere
- Plot window normalizes all vectors to unit length regardless of original magnitude
This project is open source. Feel free to use, modify, and distribute.