Matrix return

Is there a way to make this code more efficient? It works as it is at the moment but do you think it's not the best habbit to return Temp so many times?

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


Matrix Hexagon::GetV2()
{
	Matrix Temp(Vertex2);
	return Temp;
}

Matrix Hexagon::GetV3()
{
	Matrix Temp(Vertex3);
	return Temp;
}

Matrix Hexagon::GetV4()
{
	Matrix Temp(Vertex4);
	return Temp;
}

}

Matrix Hexagon::GetV6()
{
	Matrix Temp(Vertex6);
	return Temp;
}
Last edited on
I do not know what is Vertex1 - Vertex6 and what is Temp, but it seems that it would be better to write one function with a parameter

Matrix Hexagon::GetV( enum VERTEX );
You can use switch case rather than writing so many function....
What I need to do is actually get all the vertex points of the hexagon so I don't think I can use switch case as this isn't in the 'main' of my program. This is part of my header for the code. I'm thinking that I've written more lines than necessary but not sure how to shorten it. thanks

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
67
class Hexagon: public Shapes
	{
		friend ostream & operator<<(ostream &ConsoleOut, Hexagon &PointHexagon);
	private:
		double x;
		Matrix Vertex1,Vertex2,Vertex3,Vertex4,Vertex5,Vertex6;
	public:
		double xi;
		Matrix Va,Vb,Vc,Vd,Ve,Vf;

		Hexagon(){x = 0;}											
		Hexagon(double xi)										
		{
			x = xi;
	
			Matrix Va(2,1);  
			Matrix Vb(2,1);
			Matrix Vc(2,1);
			Matrix Vd(2,1);
			Matrix Ve(2,1);
			Matrix Vf(2,1);

			Va.SetMatrixData(1,1,0);
			Va.SetMatrixData(2,1,0);
			Vb.SetMatrixData(1,1,x); 
			Vb.SetMatrixData(2,1,0);
			Vc.SetMatrixData(1,1,1.5*x); 
			Vc.SetMatrixData(2,1,x*0.5*sqrt(3.0));
			Vd.SetMatrixData(1,1,x);
			Vd.SetMatrixData(2,1,x*sqrt(3.0));
			Ve.SetMatrixData(1,1,0);
			Ve.SetMatrixData(2,1,x*sqrt(3.0));
			Vf.SetMatrixData(1,1,-x*0.5);
			Vf.SetMatrixData(2,1,x*sqrt(3.0)*0.5);

			Vertex1.SetRowsColumns(2,1);
			Vertex2.SetRowsColumns(2,1);
			Vertex3.SetRowsColumns(2,1);
			Vertex4.SetRowsColumns(2,1);
			Vertex5.SetRowsColumns(2,1);
			Vertex6.SetRowsColumns(2,1);

			Vertex1 = Va;		
			Vertex2 = Vb;	
			Vertex3 = Vc;	
			Vertex4 = Vd;
			Vertex5 = Ve;	
			Vertex6 = Vf;
		}

		~Hexagon(){cout<<"Destroying Hexagon"<<endl;}

		double GetX();

		Matrix GetV1(); 
		Matrix GetV2();
		Matrix GetV3();
		Matrix GetV4();
		Matrix GetV5();
		Matrix GetV6();

		void Translate(double i, double j);
		void Rescale (double i, double j);
		void Rotate (double Theta);		
		void GetInfo();
	};
Topic archived. No new replies allowed.