5

I need to draw the figure like the following:

enter image description here

The idea is to first draw blue rectangle and then project it to XY plane. My current code is pasted below.

import graph3;
import three;
settings.outformat="pdf";
currentprojection=orthographic(1,-2,0.5);
limits((-4,-4,-0.2),(4,4,3.5));
size3(8cm,8cm,4cm);

// Draw axis
xaxis3("$x$",Arrow3);
yaxis3("$y$",Arrow3);
zaxis3("$z$",Arrow3);

// Draw blue rectangle
path3 rect1=(0.5,0.5,2)--(1.5,0.5,2)--(1.5,1.5,2)--(0.5,1.5,2)--cycle;
draw(rect1,blue);

// Construct projection and draw red rectangle
// XYplane is defined in three library
transform3 proj=planeproject(XYplane);
path3 proj=proj*rect1;
draw(proj,red);

Compilation terminated with the error:

no matching function 'planeproject(triple(pair z))'

Any idea or pointer how to proceed?

6

What planeproject expects is simply the normal vector to the plane. XYplane is an object of type triple(pair): it's actually a function that maps (x,y) to (x,y,0). The normal vector you want is simply Z.

Here's working code, obtained by replacing planeproject(XYplane) by planeproject(Z):

import graph3;
import three;
settings.outformat="pdf";
currentprojection=orthographic(1,-2,0.5);
limits((-4,-4,-0.2),(4,4,3.5));
size3(8cm,8cm,4cm);

// Draw axis
xaxis3("$x$",Arrow3);
yaxis3("$y$",Arrow3);
zaxis3("$z$",Arrow3);

// Draw blue rectangle
path3 rect1=(0.5,0.5,2)--(1.5,0.5,2)--(1.5,1.5,2)--(0.5,1.5,2)--cycle;
draw(rect1,blue);

// Construct projection and draw red rectangle
// XYplane is defined in three library
transform3 proj=planeproject(Z);
path3 proj=proj*rect1;
draw(proj,red);

The result:

enter image description here

Another general tip: It's generally preferable to make changes like settings.outformat="pdf"; before you start your imports, since some of the modules do different things depending on the settings.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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