import processing.opengl.*; int rotbool = 1; float rot = 0; float rad = 200; float gam = 300; float angle1 = 0; float angle2 = 0; float angle3 = 0; float maxangle1 = 0; float maxangle2 = 0; float [] args = { 0,0,0,0,0}; float a = (2*(rad*rad)-(gam*gam))/(2*rad); float b = -sqrt(rad*rad - a*a); float m = b/(rad-a); float [] maxangles = intersection(rad, a, b, m, args); void setup() { size(800, 600, OPENGL); noStroke(); noFill(); //smooth(); hint(ENABLE_OPENGL_4X_SMOOTH); } void draw() { maxangle1 = maxangles[0]; maxangle2 = maxangles[1]; float xloc = maxangles[2]; float yloc = maxangles[3]; float zloc = maxangles[4]; background(0); translate(width/2, 3*height/4, -10); rotateX(PI/2); rotateZ(rot); stroke(255); strokeWeight(2); ellipseMode(CENTER); ellipse(0,0,2*rad,2*rad); float a = (2*(rad*rad)-(gam*gam))/(2*rad); float b = -sqrt(rad*rad - a*a); float m = b/(rad-a); line(a,b,-rad,-(m*(-rad-a)-b)); stroke(0,255,0); strokeWeight(4); line(a,b,rad,0); // Line AB stroke(255); strokeWeight(2); stroke(255,0,0); strokeWeight(4); line(-rad,0,rad,0); // Line AD stroke(255); strokeWeight(2); //line(-rad-100,gam/2, -rad-100,-gam/2); //Line G line(-rad,-(m*(-rad-a)-b),0,-rad,.5*(m*(-rad-a)-b),0); //Line PDO if((angle1 < maxangle1)||(angle2 < maxangle2)){ line(rad,0,0,-rad,-(m*(-rad-a)-b)*cos(angle2),(m*(-rad-a)-b)*sin(angle2)); } line(-rad,0,0,-rad,-(m*(-rad-a)-b)*cos(angle2),(m*(-rad-a)-b)*sin(angle2)); line(a,b,a,-b); // Line BZ translate(rad*(1-cos(angle1)),-rad*sin(angle1),0); rotateX(PI/2); rotateY(angle1); arc(0,0,-2*rad,2*rad,0,PI); // Semicircle AD which is perpendicular to the base plane if((angle1 < maxangle1)||(angle2 < maxangle2)){ line(rad,0,-rad,0); //Diameter AD as it moves } rotateY(-angle1); rotateX(-PI/2); translate(-rad*(1-cos(angle1)),rad*sin(angle1),0); ellipseMode(CENTER); // Semicircle BMZ, perpendicular to the base plane. Formed by the motion of B. translate(a,0,0); rotateY(-PI/2); rotateZ(-PI/2); arc(0,0,2*abs(b),2*abs(b),0,angle3); rotateZ(PI/2); rotateY(PI/2); translate(-a,0,0); tatiana(angle3,rad); eugene(angle3,rad,a,b,m); if((angle1 >= maxangle1)&&(angle2 >= maxangle2)){ strokeWeight(2); line(xloc,-yloc,0,rad-2*rad*cos(angle1),-2*rad*sin(angle1),0); line(xloc,-yloc,zloc,rad-2*rad*cos(angle1),-2*rad*sin(angle1),0); line(xloc,-yloc,zloc,-rad,-(m*(-rad-a)-b)*cos(angle2),(m*(-rad-a)-b)*sin(angle2)); line(xloc,-yloc,0,xloc,-yloc,zloc); //Line KI line(a,b*cos(maxangle2),0,a,b*cos(maxangle2),abs(b)*sin(maxangle2)); //Line MTheta line(xloc,-yloc,0,a,b*cos(maxangle2),abs(b)*sin(maxangle2)); //Line MI strokeWeight(4); stroke(255,255,0); line(rad,0,0,xloc,-yloc,0); // Line AI stroke(255,128,0); line(rad,0,0,xloc,-yloc,zloc); stroke(255); } strokeWeight(2); rot = rot +.001*PI*rotbool; if(angle1 < maxangle1){ angle1 = angle1+.001*PI; } if(angle2 < maxangle2){ angle2 = angle2+.001*PI; } if (angle3 <= PI){ angle3 = angle3+.001*PI; } } void cylinder(float x, float y, float z, float r, float h, float d) { noFill(); float angle = 0; float inc = 2*PI/d; ellipseMode(CENTER); translate(0,0,h); ellipse(x,y,2*r,2*r); translate(0,0,-h); for (int i = 0; i < d; i=i+1) { noStroke(); fill(100,100,100,50); beginShape(); vertex(r*cos(angle), r*sin(angle),0); vertex(r*cos(angle+inc), r*sin(angle+inc),0); vertex(r*cos(angle+inc), r*sin(angle+inc),h); vertex(r*cos(angle), r*sin(angle),h); endShape(); angle = angle + inc; stroke(255); noFill(); } } void tatiana(float angle1, float r) { float u = 0; float v = 0; float x = 0; float y = 0; float z = 0; stroke(255,0,128); strokeWeight(4); beginShape(); for (int i = 0; i < 1000*angle1/PI; i = i+1){ u = PI+i*PI/1000; v = PI - acos(2*cos(u)+1); x = r*(1+cos(v))*cos(u) + r; y = r*(1+cos(v))*sin(u); z = r*sin(v); vertex(x,y,z); } endShape(); stroke(255); strokeWeight(1); } void eugene(float angle3, float r, float a, float b, float m){ float t = 0; float u = 0; float x = 0; float y = 0; float z = 0; stroke(0,128,255); strokeWeight(4); beginShape(); for (int i = 0; i < 1000*angle3/PI; i = i+1){ u = PI-i*PI/1000; t = (4*r*r)/(4*r*r + (cos(u))*(cos(u))*m*m*r*r + 2*(cos(u))*(cos(u))*m*m*r*a + 2*(cos(u))*(cos(u))*m*r*b + (cos(u))*(cos(u))*m*m*a*a + 2*(cos(u))*(cos(u))*m*a*b + (cos(u))*(cos(u))*b*b); x = r-2*r*t; y = t*((m*(-r-a)-b)*cos(u)); z = t*((m*(-r-a)-b)*sin(u)); vertex(x,y,z); } endShape(); strokeWeight(1); stroke(255); } float[] intersection(float r, float a, float b, float m, float[] args){ float u = 0; float uu = 0; float v = 0; float t = 0; float x1 = 0; float x2 = 0; float y1 = 0; float y2 = 0; float z1 = 0; float z2 = 0; for (int i = 0; i < 1000; i = i +1){ for (int j = 0; j < 1000; j = j+1){ u = PI-.001*PI*i; uu = PI-.001*PI*j; t = (4*r*r)/(4*r*r + (cos(uu))*(cos(uu))*m*m*r*r + 2*(cos(uu))*(cos(uu))*m*m*r*a + 2*(cos(uu))*(cos(uu))*m*r*b + (cos(uu))*(cos(uu))*m*m*a*a + 2*(cos(uu))*(cos(uu))*m*a*b + (cos(uu))*(cos(uu))*b*b); v = PI - acos(2*cos(u)+1); x1 = r-2*r*t; x2 = r*(1+cos(v))*cos(u)+r; y1 = t*(m*(-r-a)-b)*cos(uu); y2 = r*(1+cos(v))*sin(u); z1 = t*(m*(-r-a)-b)*sin(uu); z2 = r*sin(v); if(sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2)) < 1){ args[0] = PI-u; args[1] = uu; args[2] = x1; args[3] = y1; args[4] = z1; break; } } } return args; } void keyPressed() { if (key == CODED) { if (keyCode == UP) { if(rotbool == 1 || rotbool == -1){ rotbool = 0; } else if(rotbool==0) { rotbool = 1; } } if (keyCode == DOWN){ if(rotbool == 1){ rotbool = -1; } else if(rotbool==1) { rotbool = -1; } } } }