Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

In the code below, I define a cylinder (as a surface of revolution) and a plane (as a cyclic path). From both, I can get a surface that renders in 3D. Now, I would like to hide (or better remove) the part of the cylinder, which is below the surface (in this example at z < 0, rendered in a darker shade of red), while the plane should remain semi-transparent.

How can this be done elegantly?

import three;
import solids;

currentprojection = obliqueY();

path3 xyplane = path3(scale(10) * box((-1,-1),(1,1)));
revolution c =  rotate(-45,Y) * shift((0,0,-5)) *cylinder(O,1,15);

draw(surface(xyplane),black+opacity(.5));
draw(xyplane,black+linewidth(.1));

draw(surface(c),red);
draw(c,red);

Rendered image

share|improve this question
Why not drawing a white opaque surface before to draw the semi-transparent one? – Lionel MANSUY Dec 14 '12 at 13:03
@LionelMANSUY This will be part of a complex scene. I need to draw another cylinder below the xy-plane. – Jan Dec 14 '12 at 14:01
You could perhaps arrange the order of all the drawings? – Lionel MANSUY Dec 14 '12 at 14:56

1 Answer

Here's the workaround I came up with for this particular example. If the surface, you want to cut is a surface of revolution, you can define it as a parametric surface excluding the part below the plane. However, this is not a generic answer to the question.

import three;
import solids;

currentprojection = obliqueY();

path3 xyplane = path3(scale(10) * box((-1,-1),(1,1)));

surface cylinderSurfaceTiltedPlane(real R, real z0, real planeAlpha, real planePhi) {
    triple parametricCylinder(pair p) {
        real Phi = p.x;
        real Z = p.y;
        real x = R*sin(Phi);
        real y = R*cos(Phi);
        real z = Z * (tan(planeAlpha*pi/180)*sin(Phi - planePhi*pi/180)*R + z0)/z0;
        return (x,y,z);
    }
    return surface(parametricCylinder, (0,0), (2pi,z0), Spline);
}


draw(surface(xyplane),black+opacity(.5));
draw(xyplane,black+linewidth(.1));

surface cF = rotate(180-45,Y)  * shift((0,0,-10)) *     cylinderSurfaceTiltedPlane(1, 10, -45, 0);
draw(cF,red);

rendered image

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.