How to rotate a source efficiently in two dimensions?

I would like to rotate a particle gun by 360° in 1° steps around a fixed center point in two dimensions. I’ve sketched my goal:

The particle gun itself has to be rotated itself accordingly. So not only the absolute position needs to describe a circular movement but the particle gun should also point towards the center all the time.
Is there a smart and/or convenient way to realize this?

I’ve seen How to rotate a source in a macro file? but when I understood correctly it is limited to change by 180° only and the discussion is also more about histograms(…?).

Got the absolute positioning working by:

double R = whatever_value;
double x, y = 0;
double angle = 0;

for(int i=0; i<360; i++){
	angle = i;
	angle = 2*3.14159265358979311600*(angle * 0.00277777777);
	x = R*cos(angle);
	y = R*sin(angle);
	G4ThreeVector pos3(x*cm, y*cm, 0*m);

The facing towards the center is probably now straight forward.

Geant4 does have constants for things like pi.

#include "G4PhysicalConstants.hh"

And it has units, so you can write, e.g., angle = i*deg;.

#include "G4SystemOfUnits.hh"
1 Like