Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- struct Vect {
- double vx;
- double vy;
- double vz;
- };
- void print_v(Vect v){
- cout << v.vx << "i + " << v.vy << "j + " << v.vz << "k" << endl;
- }
- double len(Vect v){ return pow(v.vx * v.vx + v.vy * v.vy + v.vz * v.vz, 0.5); }
- double scalar_mult(Vect v1, Vect v2){
- return v1.vx * v2.vx + v1.vy * v2.vy + v1.vz * v2.vz;
- }
- Vect vector_mult(Vect v1, Vect v2){
- Vect res;
- res.vx = v1.vy * v2.vz - v1.vz * v2.vy;
- res.vy = v1.vz * v2.vx - v1.vx * v2.vz;
- res.vz = v1.vx * v2.vy - v1.vy * v2.vx;
- return res;
- }
- int main() {
- Vect a;
- Vect b;
- a.vx = 1; a.vy = 2; a.vz = 0;
- b.vx = 0; b.vy = 1; b.vz = 0;
- cout << "Длина вектора a: " << len(a) << endl;
- cout << "Длина вектора b: " << len(b) << endl;
- cout << "Скалярное произведение (a, b): " << scalar_mult(a, b) << endl;
- cout << "Векторное произведение [a × b]: "; print_v(vector_mult(a, b));
- cout << "cos(a, b): " << scalar_mult(a, b) / (len(a) * len(b)) << endl;
- cout << "sin(a, b): " << len(vector_mult(a, b)) / (len(a) * len(b)) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement