Skip to content

Commit

Permalink
renormalize dir vector after each rotation, suggested by @ShijieYan
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Sep 1, 2023
1 parent 4fe8e43 commit b0bad9f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/mcx_core.cu
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,11 @@ __device__ inline void rotatevector2d(MCXdir* v, float stheta, float ctheta) {
v->nscat
);

float tmp0 = rsqrtf(v->x * v->x + v->y * v->y + v->z * v->z);
v->x *= tmp0;
v->y *= tmp0;
v->z *= tmp0;

GPUDEBUG(("new dir: %10.5e %10.5e %10.5e\n", v->x, v->y, v->z));
}

Expand Down Expand Up @@ -964,6 +969,11 @@ __device__ inline void rotatevector(MCXdir* v, float stheta, float ctheta, float
*((float4*)v) = float4(stheta * cphi, stheta * sphi, (v->z > 0.f) ? ctheta : -ctheta, v->nscat);
}

float tmp0 = rsqrtf(v->x * v->x + v->y * v->y + v->z * v->z);
v->x *= tmp0;
v->y *= tmp0;
v->z *= tmp0;

GPUDEBUG(("new dir: %10.5e %10.5e %10.5e\n", v->x, v->y, v->z));
}

Expand Down

0 comments on commit b0bad9f

Please sign in to comment.