Possible Duplicate:
How to pass objects to functions in C++?
My main program gives me coefficient of plane equation as a vector.
I have many planes and I am trying to find out their intersections. So, I have series of plane parameters, belongs to each plane and I have created a map to accommodate plane parameters and I gave a key as plane number. Now, I am calling planes according to randomly given order (that is why, I use map). So, for each time I am using two planes to compare whether they intersect or not.
My function:
vector<double> intersection_vector(vector<double> plane1,vector<double> plane2){
vector<double> cross_product;
double a1=plane1.at(0);
double b1=plane1.at(1);
double a2=plane2.at(0);
double b2=plane2.at(1);
//double d1=plane1.at(2);
//double d2=plane2.at(2);
int c1=-1,c2=-1;
double cross_a=(b1*c2)-(b2*c1);
double cross_b=(a2*c1)-(a1*c2);
double cross_c=(a1*b2)-(a2*b1);
cross_product.push_back(cross_a);cross_product.push_back(cross_b);cross_product.push_back(cross_c);
return cross_product;
}
Main program:
//some codes
map<int, vector<int> >::iterator xx;
for (xx=parameter_list.begin();xx!= parameter _list.end();xx++){
int my_plane=xx->first;
vector <int> your_planes=xx->second;
for(int i=0; i< your _planes.size();i++){
int any_ your _plane= your _planes.at(i);
vector <double>edge_line=intersection_vector(my_plane, any_ your _plane);
// do something
Now, I want to use pointers and references to speed up this process. Please help me while explaining why use *
and &
for respective places. (Maybe I need call by reference or something else and what I did is call by value? Is that, plase explain because, I do not have basic on this).