Для представления 4D-вектора в C++ можно использовать различные подходы. Вот несколько методов:
Метод 1: использование массива
#include <iostream>
int main() {
float vector[4] = {1.0f, 2.0f, 3.0f, 4.0f};
// Accessing individual components
float x = vector[0];
float y = vector[1];
float z = vector[2];
float w = vector[3];
// Output
std::cout << "Vector: (" << x << ", " << y << ", " << z << ", " << w << ")" << std::endl;
return 0;
}
Метод 2: использование структуры
#include <iostream>
struct Vector4D {
float x;
float y;
float z;
float w;
};
int main() {
Vector4D vector = {1.0f, 2.0f, 3.0f, 4.0f};
// Accessing individual components
float x = vector.x;
float y = vector.y;
float z = vector.z;
float w = vector.w;
// Output
std::cout << "Vector: (" << x << ", " << y << ", " << z << ", " << w << ")" << std::endl;
return 0;
}
Метод 3. Использование класса
#include <iostream>
class Vector4D {
public:
float x;
float y;
float z;
float w;
Vector4D(float x_, float y_, float z_, float w_) : x(x_), y(y_), z(z_), w(w_) {}
};
int main() {
Vector4D vector(1.0f, 2.0f, 3.0f, 4.0f);
// Accessing individual components
float x = vector.x;
float y = vector.y;
float z = vector.z;
float w = vector.w;
// Output
std::cout << "Vector: (" << x << ", " << y << ", " << z << ", " << w << ")" << std::endl;
return 0;
}
Это всего лишь несколько примеров представления четырехмерного вектора на C++. Вы можете выбрать метод, который лучше всего соответствует вашим потребностям.