forked from Annex5061/java-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrossProduct.cpp
66 lines (53 loc) · 1.21 KB
/
CrossProduct.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
using namespace std;
template <class T>
class vector
{
public:
T *arr;
int size;
vector(int m)
{
size = m;
arr = new T[size];
}
T crossproduct(vector &v /*,vector &v3*/)
{
int a;
for (int i = 0; i < size; i++)
{
a= ((arr[i + 1] * v.arr[i + 2]) - (arr[i + 2] * v.arr[i + 1]));
a = ((arr[i + 2] * v.arr[i + 0]) - (arr[i + 0] * v.arr[i + 0]));
a= ((arr[i + 0] * v.arr[i + 1]) - (arr[i + 1] * v.arr[i + 0]));
}
return a;
}
void display()
{
int d[size]= crossproduct();
return d;
}
};
int main()
{
vector<int> v1(3), v2(3);
v1.arr[0] = 1;
v1.arr[1] = 2;
v1.arr[2] = 3;
v2.arr[0] = 3;
v2.arr[1] = 2;
v2.arr[2] = 1;
v1.crossproduct(v2);
v1.display();
//int d[size] = v1.crossproduct(v2);
//for(int j=0;j<3;j++)
//{
//
// cout<<d[j]<<endl;
//}
//cout<<d<<endl;
//cout<<d[0]<<endl;
//cout<<d[1]<<endl;
//cout<<d[2]<<endl;
return 0;
}