Shift vector in x axis (Lorentz boost)

The rest of my code seem to work alright without the section on the "Lorentz boost". I'm not sure how I should approach this - I have to shift my 4-vector by "boosting it". Am I on the right track? - what should I return in the Boost function and how should I call it in the main? 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148

#include<iostream>
#include<cmath>
using namespace std;

//=============================================================================
//Vector 3
//=============================================================================

class Vector3
	{
		// Friends 
		//Prototypes overloading of << operator
		friend ostream & operator << (ostream &os, const Vector3 &v3);
		
	protected:
		double x; double y; double z;
		
	public:
		double xi; double yi; double zi;
		
		//Default constructor
		Vector3(){x=y=z=0;}
		
		//parameterised constructor
		Vector3(double xi, double yi, double zi)
		{x=xi; y=yi; z=zi;}
		
		//destructor
		~Vector3(){};
		
		//Acessor functions
		double Getx() const {return x;}
		double Gety() const {return y;}
		double Getz() const {return z;}
		
		//Scalar product function
		double scalar(Vector3 v3) const
		{
			double temp;
			temp=x*v3.Getx()+y*v3.Gety()+z*v3.Getz();
			return temp;
		}
		
		//Overload () operator
		Vector3 operator() (double a, double b,double c)
		{return Vector3(a,b,c);}
	};

//Overload << operator for Vector3
ostream & operator<<(ostream & os, const Vector3 &v3)
{
	os<<"("<<v3.Getx()<<","<<v3.Gety()<<","<<v3.Getz()<<")"<<endl;
	return os;
}
//=============================================================================
// Vector 4
//=============================================================================

//Overload << operator for Vector4
class Vector4 : public Vector3
	{
		friend ostream & operator<<(ostream & os, const Vector4 &v4);
		
	protected:
		double a; double b; double c; double ct;
		
	public:
		double ai; double bi; double ci; double cti;
		
		//Default constructor
		Vector4(){a=b=c=ct=0;} 
		
		//Paramaterised constructor
		Vector4(double ai, double bi, double ci, double cti) 
		{a=ai; b=bi; c=ci; ct=cti;}
		
		~Vector4(){}; //destructor
		
		//Accessor functions
		double Getx(){return a;}
		double Gety(){return b;}
		double Getz(){return c;}
		double Getct(){return ct;}
		
		//Scalar product function
		double scalar(Vector4 v4) const
		{
			double temp;
			temp=a*v4.Getx()+b*v4.Gety()+c*v4.Getz()+ct*v4.Getct();
			return temp;
		}
		
		//Lorentz boost functions
		double Boost(Vector4 v4) const
		{
			double Beta; double Gamma; 
			double BOOSTct; double BOOSTx; double BOOSTy; double BOOSTz; 
			double const LightSpeed=3e8; double const Velocity=2.8e8;
			Beta=Velocity/LightSpeed;
			Gamma=1/sqrt(1-Beta*Beta);
			BOOSTct=Gamma*(ct-Beta*a);
			BOOSTx=Gamma*(a-Beta*ct);
			BOOSTy=b;
			BOOSTz=c;
			
			
		}
		
		//double scalar
		
	};

ostream & operator << (ostream & os, Vector4 &v4)
{
	os<<"("<<v4.Getx()<<","<<v4.Gety()<<","<<v4.Getz()<<","<<v4.Getct()<<")"<<endl;
	return os;
}

//=============================================================================
int main(void)
{
	Vector3 v1;
	cout<<v1<<endl;
	
	Vector3 v2(1,2,3);
	cout<<v2<<endl;
	
	Vector3 v3(10,11,12);
	cout<<v3<<endl;
	
	cout<<"Scalar product of Vector 2 and 3:"<<endl;
	cout<<v2.scalar(v3)<<endl;
	
	
	Vector4 v4(2,3,4,5);
	cout<<v4<<endl;
	
	Vector4 v5(6,7,8,9);
	cout<<v5<<endl;
	
	cout<<"Scalar product of Vector 4 and 5:"<<endl;
	cout<<v4.scalar(v5)<<endl;
	

	
}
closed account (D80DSL3A)
I'm not sure what you mean by "boost". 4-vectors can be added just as 3-vectors can be, element by element. Perhaps your Boost function should return the sum of two Vector4 objects?
1
2
3
4
Vector4 Boost(Vector4 v4) const
{
    return Vector4( a+v4.a, b+v4.b, c+v4.c, ct+v4.ct);
}

It looks like you are applying a Lorentz transformation there currently, but to what?

I think your scalar() function calculation is wrong. Squared length is:
temp=ct*v4.Getct()-( a*v4.Getx()+b*v4.Gety()+c*v4.Getz() );

Other problems with your code. You have multiple duplication of data members (x,y,z:xi,yi,zi) in the Vector3 base class. What are xi,yi,zi for?
You then add another full set of coordinates in the Vector4 class (a,b,c,ct:ai,bi,cti) instead of using the xi,yi,zi inherited from Vector3.
I'm not sure what a call to getX() would get you. There is a version of getX() in each class, but they are non-virtual, differing only in their const-ness on the calling object. If the const (base) version gets called it will return the uninitialized value of x for a Vector4 object. Quite messy.
I've added this to the Lorentz transformation part. But i'm not sure what to return after this function. I need a vector to be returned but my function only returns a double, right?


1
2
3
4
5
6
7
8
9
10
11
12
13
14

		double LorentzTransformation(Vector4 v5) const
		{
			double Beta; double Gamma; 
			double TRANSct; double TRANSx; double TRANSy; double TRANSz; 
			double const LightSpeed=3e8; double const Velocity=2.8e8;
			Beta=Velocity/LightSpeed;
			Gamma=1/sqrt(1-Beta*Beta);
			TRANSct=Gamma*(v5.Getct()-Beta*v5.Getx());
			TRANSx=Gamma*(v5.Getx()-Beta*v5.Getct());
			TRANSy=v5.Gety();
			TRANSz=v5.Getz();
		}
closed account (D80DSL3A)
OK. I think you're trying to apply the transformation to the calling Vector4 object (4-vector in unprimed frame) to produce the 4-vector in the primed (observers) frame of reference. The needed parameter would be the relative velocity between the reference frames. If the relative motion is along the x-axis only then a double would do.

It's been a lot of years since I studied relativity (college years), but here's my next guess at what you're looking for:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// transform applied using the calling Vector4 object (this).
Vector4 LorentzTransformation(double v) const// v is relative velocity along the x-axis.
{
    const double LightSpeed=3e8;// defining constant    
    double Beta = v/LightSpeed;
    double Gamma = 1/sqrt(1-Beta*Beta);

    // apply transformation and return result vPrime
    Vector4 vPrime;
    vPrime.ct = Gamma*( Getct()-Beta*Getx() );
    vPrime.a = Gamma*( Getx()-Beta*Getct() );
    vPrime.b = Gety();
    vPrime.c = Getz();
    return vPrime;
}

EDIT: comments in code.
Also, in review I see the term 'boost' is appropriate. Your function name was fine.
Last edited on
Thank you for your help. I had to remove the "const" after "Vector4 LorentzTransformation(double v)" in order to remove the error that popped up. Is that still ok?

Then I tried calling the function in my main but I am having trouble here.

1
2
3
4
5

double a; double v;
	a=v4.LorentzTransformation( v);
	v=1.2;
	cout<<"Lorentz transformation of Vector 5:"<<v4<<endl;

Topic archived. No new replies allowed.