Skip to content

Instantly share code, notes, and snippets.

@tai2
Created November 6, 2014 07:18
Show Gist options
  • Select an option

  • Save tai2/4f6f4d86a58129dbf511 to your computer and use it in GitHub Desktop.

Select an option

Save tai2/4f6f4d86a58129dbf511 to your computer and use it in GitHub Desktop.
circle on sphere detection
size(512, 512, P3D);
colorMode(RGB, 1.0);
noSmooth();
camera(5.0, 0.0, 0.0, 0, 0, 0, 0, 0, -1);
perspective(PI / 6.0, 1.0, -5.0, 5.0);
float R = 30;
float LAT = -45;
float LNG = 90;
float c_p = radians(LNG);
float c_t = radians(90 - LAT);
float nx = sin(c_t) * cos(c_p);
float ny = sin(c_t) * sin(c_p);
float nz = cos(c_t);
float c_t0 = radians(90 - LAT + R);
float ptx = sin(c_t0) * cos(c_p);
float pty = sin(c_t0) * sin(c_p);
float ptz = cos(c_t0);
float d = - (nx * ptx + ny * pty + nz * ptz);
println("nx=" + nx);
println("ny=" + ny);
println("nz=" + nz);
println("n len=" + sqrt(nx * nx + ny * ny + nz * nz));
println("ptx=" + ptx);
println("pty=" + pty);
println("ptz=" + ptz);
println("pt len=" + sqrt(ptx * ptx + pty * pty + ptz * ptz));
println("d=" + d);
for (float lng = -180; lng < 180; lng += 3) {
for (float lat = -90; lat < 90; lat += 3) {
float p = radians(lng);
float t = radians(90 - lat);
float x = sin(t) * cos(p);
float y = sin(t) * sin(p);
float z = cos(t);
float r, g, b, a;
if (nx * x + ny * y + nz * z + d > 0) {
r = 1.0; g = 0.0; b = 0.0; a = 1.0;
} else {
r = 0.0; g = 0.0; b = 0.0; a = 0.5;
}
stroke(color(r, g, b, a));
point(x, y, z);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment