Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 10 additions & 40 deletions mcxtrace-comps/contrib/Mirror_toroid_pothole.comp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ MCDISPLAY
// Because the code above doesn't actually reproduce a torus exactly but uses a cylinder and an ellipsoid to construct the toroidal mirror (to avoid solving
// quartic equations), there's a slight mismatch between the 3D view (exact torus) and the actual toroidal mirror coded above.

double x0, y0, z0, x1, y1, z1, theta, phi, phi_total, theta_total, theta_beginning, phi_beginning, theta_end, phi_end;
double theta, phi, phi_total, theta_total, theta_beginning, phi_beginning, theta_end, phi_end;
// int N=50; too many points, makes the 3D matlab viewer bug
int N = 10;

Expand All @@ -221,46 +221,16 @@ MCDISPLAY
theta_end = theta + (theta_total / 2);
phi_end = phi + (phi_total / 2);

theta = theta_beginning;
phi = phi_beginning;

while (theta <= theta_end) {
phi = 180 - (phi_total / 2);
x0 = radius * sin (DEG2RAD * theta);
y0 = (radius_o + radius * cos (DEG2RAD * theta)) * cos (DEG2RAD * phi) + (radius_o + radius);
z0 = (radius_o + radius * cos (DEG2RAD * theta)) * sin (DEG2RAD * phi);
while (phi <= phi_end) {
x1 = radius * sin (DEG2RAD * theta);
y1 = (radius_o + radius * cos (DEG2RAD * theta)) * cos (DEG2RAD * phi) + (radius_o + radius);
z1 = (radius_o + radius * cos (DEG2RAD * theta)) * sin (DEG2RAD * phi);
line (x0, y0, z0, x1, y1, z1);
x0 = x1;
y0 = y1;
z0 = z1;
phi += phi_total / N;
}
theta += theta_total / N;
}

theta = theta_beginning;
phi = phi_beginning;

while (phi <= phi_end) {
theta = -(theta_total / 2);
x0 = radius * sin (DEG2RAD * theta);
y0 = (radius_o + radius * cos (DEG2RAD * theta)) * cos (DEG2RAD * phi) + (radius_o + radius);
z0 = (radius_o + radius * cos (DEG2RAD * theta)) * sin (DEG2RAD * phi);
while (theta <= theta_end) {
x1 = radius * sin (DEG2RAD * theta);
y1 = (radius_o + radius * cos (DEG2RAD * theta)) * cos (DEG2RAD * phi) + (radius_o + radius);
z1 = (radius_o + radius * cos (DEG2RAD * theta)) * sin (DEG2RAD * phi);
line (x0, y0, z0, x1, y1, z1);
x0 = x1;
y0 = y1;
z0 = z1;
theta += theta_total / N;
int i, j;
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
double t0 = DEG2RAD * (theta_beginning + i * theta_total / N), t1 = DEG2RAD * (theta_beginning + (i + 1) * theta_total / N);
double p0 = DEG2RAD * (phi_beginning + j * phi_total / N), p1 = DEG2RAD * (phi_beginning + (j + 1) * phi_total / N);
polygon (4, radius * sin (t0), (radius_o + radius * cos (t0)) * cos (p0) + (radius_o + radius), (radius_o + radius * cos (t0)) * sin (p0),
radius * sin (t1), (radius_o + radius * cos (t1)) * cos (p0) + (radius_o + radius), (radius_o + radius * cos (t1)) * sin (p0), radius * sin (t1),
(radius_o + radius * cos (t1)) * cos (p1) + (radius_o + radius), (radius_o + radius * cos (t1)) * sin (p1), radius * sin (t0),
(radius_o + radius * cos (t0)) * cos (p1) + (radius_o + radius), (radius_o + radius * cos (t0)) * sin (p1));
}
phi += phi_total / N;
}
%}

Expand Down
7 changes: 1 addition & 6 deletions mcxtrace-comps/optics/Capillary.comp
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,7 @@ TRACE

MCDISPLAY
%{
circle ("xy", 0, 0, 0, radius);
circle ("xy", 0, 0, length, radius);
line (radius, 0, 0, radius, 0, length);
line (0, radius, 0, 0, radius, length);
line (-radius, 0, 0, -radius, 0, length);
line (0, -radius, 0, 0, -radius, length);
cylinder (0, 0, length / 2.0, radius, length, 0, 0, 0, 1);
%}

END
10 changes: 2 additions & 8 deletions mcxtrace-comps/optics/Mirror.comp
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,9 @@ MCDISPLAY
if (shape == ANY) { /* OFF file */
off_display (offdata);
} else if (yheight) {
line (0, -yheight / 2.0, -zdepth / 2.0, 0, yheight / 2.0, -zdepth / 2.0);
line (0, -yheight / 2.0, zdepth / 2.0, 0, yheight / 2.0, zdepth / 2.0);
line (0, -yheight / 2.0, -zdepth / 2.0, 0, -yheight / 2.0, zdepth / 2.0);
line (0, yheight / 2.0, -zdepth / 2.0, 0, yheight / 2.0, zdepth / 2.0);
polygon (4, 0.0, -yheight / 2.0, -zdepth / 2.0, 0.0, yheight / 2.0, -zdepth / 2.0, 0.0, yheight / 2.0, zdepth / 2.0, 0.0, -yheight / 2.0, zdepth / 2.0);
} else {
line (-xwidth / 2.0, 0, -zdepth / 2.0, xwidth / 2.0, 0, -zdepth / 2.0);
line (-xwidth / 2.0, 0, zdepth / 2.0, xwidth / 2.0, 0, zdepth / 2.0);
line (-xwidth / 2.0, 0, -zdepth / 2.0, -xwidth / 2.0, 0, zdepth / 2.0);
line (xwidth / 2.0, 0, -zdepth / 2.0, xwidth / 2.0, 0, zdepth / 2.0);
polygon (4, -xwidth / 2.0, 0.0, -zdepth / 2.0, xwidth / 2.0, 0.0, -zdepth / 2.0, xwidth / 2.0, 0.0, zdepth / 2.0, -xwidth / 2.0, 0.0, zdepth / 2.0);
}
%}

Expand Down
5 changes: 1 addition & 4 deletions mcxtrace-comps/optics/Mirror_curved.comp
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,13 @@ MCDISPLAY
alpha = -(zdepth / 2.0) / fabs (radius);
x0 = radius * (1 - cos (alpha));
z0 = radius * sin (alpha);
line (x0, y0, z0, x0, y1, z0);
while (alpha < (zdepth / 2.0 / fabs (radius))) {
alpha += zdepth / N / fabs (radius);
x1 = radius * (1 - cos (alpha));
z1 = radius * sin (alpha);
line (x0, y0, z0, x1, y0, z1);
line (x0, y1, z0, x1, y1, z1);
polygon (4, x0, y0, z0, x0, y1, z0, x1, y1, z1, x1, y0, z1);
x0 = x1;
z0 = z1;
line (x0, y0, z0, x0, y1, z0);
}
%}

Expand Down
33 changes: 10 additions & 23 deletions mcxtrace-comps/optics/Mirror_elliptic.comp
Original file line number Diff line number Diff line change
Expand Up @@ -194,34 +194,21 @@ TRACE
MCDISPLAY
%{
int i, j, N = 12;
double t, xx, yy, zz, xx0, yy0, zz0;
double a2, b2, c2;
a2 = 1.0 / a2inv;
b2 = 1.0 / b2inv;
c2 = 1.0 / c2inv;
if (xwidth && zdepth) {
for (i = 0; i < N; i++) {
xx0 = -xwidth / 2.0;
zz = i * zdepth / (N - 1) - zdepth / 2.0;
yy0 = -(1) * sqrt (b2 * (1 - xx0 * xx0 / a2 - zz * zz / c2)) + sqrt (b2);
for (j = 1; j < N; j++) {
xx = j * xwidth / (N - 1) - xwidth / 2.0;
yy = -(1) * sqrt (b2 * (1 - xx * xx / a2 - zz * zz / c2)) + sqrt (b2);
line (xx0, yy0, zz, xx, yy, zz);
xx0 = xx;
yy0 = yy;
}
}
for (i = 0; i < N; i++) {
zz0 = -zdepth / 2.0;
xx = i * xwidth / (N - 1) - xwidth / 2.0;
yy0 = -(1) * sqrt (b2 * (1 - xx * xx / a2 - zz0 * zz0 / c2)) + sqrt (b2);
for (j = 1; j < N; j++) {
zz = j * zdepth / (N - 1) - zdepth / 2.0;
yy = -(1) * sqrt (b2 * (1 - xx * xx / a2 - zz * zz / c2)) + sqrt (b2);
line (xx, yy0, zz0, xx, yy, zz);
zz0 = zz;
yy0 = yy;
double dx = xwidth / (N - 1), dz = zdepth / (N - 1);
for (i = 0; i < N - 1; i++) {
for (j = 0; j < N - 1; j++) {
double x0 = i * dx - xwidth / 2.0, x1 = x0 + dx;
double z0 = j * dz - zdepth / 2.0, z1 = z0 + dz;
double y00 = -sqrt (b2 * (1 - x0 * x0 / a2 - z0 * z0 / c2)) + sqrt (b2);
double y10 = -sqrt (b2 * (1 - x1 * x1 / a2 - z0 * z0 / c2)) + sqrt (b2);
double y11 = -sqrt (b2 * (1 - x1 * x1 / a2 - z1 * z1 / c2)) + sqrt (b2);
double y01 = -sqrt (b2 * (1 - x0 * x0 / a2 - z1 * z1 / c2)) + sqrt (b2);
polygon (4, x0, y00, z0, x1, y10, z0, x1, y11, z1, x0, y01, z1);
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions mcxtrace-comps/optics/Mirror_parabolic.comp
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,7 @@ MCDISPLAY
y[2] = x0 * x0 * a2inv + z1 * z1 * b2inv;
y[3] = x1 * x1 * a2inv + z1 * z1 * b2inv;

line (x0, y[0], z0, x1, y[1], z0);
line (x0, y[0], z0, x0, y[2], z1);
if (i == Ni - 1)
line (x1, y[1], z0, x1, y[3], z1);
if (j == Nj - 1)
line (x0, y[2], z1, x1, y[3], z1);
polygon (4, x0, y[0], z0, x1, y[1], z0, x1, y[3], z1, x0, y[2], z1);
}
}
%}
Expand Down
50 changes: 10 additions & 40 deletions mcxtrace-comps/optics/Mirror_toroid.comp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ MCDISPLAY
// Because the code above doesn't actually reproduce a torus exactly but uses a cylinder and an ellipsoid to construct the toroidal mirror (to avoid solving
// quartic equations), there's a slight mismatch between the 3D view (exact torus) and the actual toroidal mirror coded above.

double x0, y0, z0, x1, y1, z1, theta, phi, phi_total, theta_total, theta_beginning, phi_beginning, theta_end, phi_end;
double theta, phi, phi_total, theta_total, theta_beginning, phi_beginning, theta_end, phi_end;
// int N=50; too many points, makes the 3D matlab viewer bug
int N = 10;

Expand All @@ -155,46 +155,16 @@ MCDISPLAY
theta_end = theta + (theta_total / 2);
phi_end = phi + (phi_total / 2);

theta = theta_beginning;
phi = phi_beginning;

while (theta <= theta_end) {
phi = 180 - (phi_total / 2);
x0 = radius * sin (DEG2RAD * theta);
y0 = (radius_o + radius * cos (DEG2RAD * theta)) * cos (DEG2RAD * phi) + (radius_o + radius);
z0 = (radius_o + radius * cos (DEG2RAD * theta)) * sin (DEG2RAD * phi);
while (phi <= phi_end) {
x1 = radius * sin (DEG2RAD * theta);
y1 = (radius_o + radius * cos (DEG2RAD * theta)) * cos (DEG2RAD * phi) + (radius_o + radius);
z1 = (radius_o + radius * cos (DEG2RAD * theta)) * sin (DEG2RAD * phi);
line (x0, y0, z0, x1, y1, z1);
x0 = x1;
y0 = y1;
z0 = z1;
phi += phi_total / N;
int i, j;
for (i = 0; i < N; i++) {
for (j = 0; j < N; j++) {
double t0 = DEG2RAD * (theta_beginning + i * theta_total / N), t1 = DEG2RAD * (theta_beginning + (i + 1) * theta_total / N);
double p0 = DEG2RAD * (phi_beginning + j * phi_total / N), p1 = DEG2RAD * (phi_beginning + (j + 1) * phi_total / N);
polygon (4, radius * sin (t0), (radius_o + radius * cos (t0)) * cos (p0) + (radius_o + radius), (radius_o + radius * cos (t0)) * sin (p0),
radius * sin (t1), (radius_o + radius * cos (t1)) * cos (p0) + (radius_o + radius), (radius_o + radius * cos (t1)) * sin (p0), radius * sin (t1),
(radius_o + radius * cos (t1)) * cos (p1) + (radius_o + radius), (radius_o + radius * cos (t1)) * sin (p1), radius * sin (t0),
(radius_o + radius * cos (t0)) * cos (p1) + (radius_o + radius), (radius_o + radius * cos (t0)) * sin (p1));
}
theta += theta_total / N;
}

theta = theta_beginning;
phi = phi_beginning;

while (phi <= phi_end) {
theta = -(theta_total / 2);
x0 = radius * sin (DEG2RAD * theta);
y0 = (radius_o + radius * cos (DEG2RAD * theta)) * cos (DEG2RAD * phi) + (radius_o + radius);
z0 = (radius_o + radius * cos (DEG2RAD * theta)) * sin (DEG2RAD * phi);
while (theta <= theta_end) {
x1 = radius * sin (DEG2RAD * theta);
y1 = (radius_o + radius * cos (DEG2RAD * theta)) * cos (DEG2RAD * phi) + (radius_o + radius);
z1 = (radius_o + radius * cos (DEG2RAD * theta)) * sin (DEG2RAD * phi);
line (x0, y0, z0, x1, y1, z1);
x0 = x1;
y0 = y1;
z0 = z1;
theta += theta_total / N;
}
phi += phi_total / N;
}
line (-xwidth / 2.0, 0, -zdepth / 2.0, xwidth / 2.0, 0, -zdepth / 2.0);
line (-xwidth / 2.0, 0, zdepth / 2.0, xwidth / 2.0, 0, zdepth / 2.0);
Expand Down
37 changes: 13 additions & 24 deletions mcxtrace-comps/optics/Multilayer_elliptic.comp
Original file line number Diff line number Diff line change
Expand Up @@ -232,31 +232,20 @@ TRACE

MCDISPLAY
%{
/*
rectangle("xz",0,0,0,width,length); */
int i, j, NN = 10;
double x0, y0, z0;
double x1, y1, z1, z_el, y_el;

x0 = -width / 2.0;

for (i = 0; i <= NN; i++) {
z0 = -length / 2.0;
z_el = cos (xi) * z0 + Z0; // transformation to EL reference frame
int j, NN = 10;
double z0, y0, z1, y1, z_el, y_el;
z0 = -length / 2.0;
z_el = cos (xi) * z0 + Z0; // transformation to EL reference frame
y_el = b * sqrt (1.0 - ((z_el * z_el) / (a * a)));
y0 = cos (xi) * (y_el - Y0) - sin (xi) * (z_el - Z0);
for (j = 0; j < NN; j++) {
z1 = z0 + length / NN;
z_el = cos (xi) * z1 + Z0;
y_el = b * sqrt (1.0 - ((z_el * z_el) / (a * a)));
y0 = cos (xi) * (y_el - Y0) - sin (xi) * (z_el - Z0);
line (-width / 2, y0, z0, width / 2, y0, z0);
for (j = 0; j <= NN; j++) {
z1 = z0 + length / NN;
z_el = cos (xi) * z1 + Z0;
y_el = b * sqrt (1.0 - ((z_el * z_el) / (a * a)));
y1 = cos (xi) * (y_el - Y0) - sin (xi) * (z_el - Z0);
line (x0, y0, z0, x0, y1, z1);
y0 = y1;
z0 = z1;
line (-width / 2, y1, z1, width / 2, y1, z1);
}
x0 = x0 + width / NN;
y1 = cos (xi) * (y_el - Y0) - sin (xi) * (z_el - Z0);
polygon (4, -width / 2.0, y0, z0, width / 2.0, y0, z0, width / 2.0, y1, z1, -width / 2.0, y1, z1);
y0 = y1;
z0 = z1;
}
%}

Expand Down
Loading