Difference between revisions of "Asymptote: Crash Course"
m (→Current projection) (Tag: Blanking) |
m (undoing vandalism) |
||
Line 1: | Line 1: | ||
+ | == Current projection == | ||
+ | Suppose you are floating in a three-dimensional universe that extends infinitely in each direction. A bright source of light illuminates the scene. You can move freely around this universe, enabling you to see everything in different perspectives. | ||
+ | |||
+ | At this point, there is a giant grid with a sphere on it. From your point of view, it looks like this: | ||
+ | |||
+ | <asy>size(300); | ||
+ | |||
+ | import three; | ||
+ | |||
+ | currentprojection = perspective(1.7,0.5,0.6); | ||
+ | currentlight = Viewport; | ||
+ | |||
+ | for (int i=-20; i<=10; i+=1) | ||
+ | draw((i,-20,0)--(i,10,0)); | ||
+ | for (int j=-20; j<=10; j+=1) | ||
+ | draw((-20,j,0)--(10,j,0)); | ||
+ | |||
+ | draw(scale(2,2,2)*unitsphere, red); | ||
+ | </asy> | ||
+ | |||
+ | This is what perspective projection is like. Basically, it is as if you were floating in this universe looking at the object with your own eyes. Closer objects are larger than farther objects, parallel lines converge, and, most importantly, I don't get dizzy. | ||
+ | |||
+ | Now, suppose you wore glasses that nuked your sense of perspective and replaced it with a different world, a world where parallel lines stay parallel and closer objects are of the same size as farther objects. This is what you'd see: | ||
+ | |||
+ | <asy>size(300); | ||
+ | |||
+ | import three; | ||
+ | |||
+ | currentprojection = orthographic(1.7,0.5,0.6); | ||
+ | currentlight = Viewport; | ||
+ | |||
+ | for (int i=-20; i<=10; i+=1) | ||
+ | draw((i,-20,0)--(i,10,0)); | ||
+ | for (int j=-20; j<=10; j+=1) | ||
+ | draw((-20,j,0)--(10,j,0)); | ||
+ | |||
+ | draw(scale(2,2,2)*unitsphere, red); | ||
+ | </asy> | ||
+ | |||
+ | This, my friends, is orthographic projection. It's not natural, but it's very useful when you want everything to be at the same scale, regardless of distance. | ||
+ | |||
+ | So now that we've figured out exactly what the heck are perspective and orthogonal projection, let's find out how to do it in Asymptote. | ||
+ | |||
+ | Declaring projection is easy: | ||
+ | |||
+ | // Perspective | ||
+ | currentprojection = perspective(camera=(x,y,z)); | ||
+ | // Orthographic | ||
+ | currentprojection = orthographic(camera=(x,y,z)); | ||
+ | |||
+ | Here, <tt>camera=(x,y,z)</tt> states the position of the camera, whose viewpoint the reader sees the drawing from. In our hypothetical universe, this would be the exact same thing as defining your position. Asymptote dictates that the <math>z</math>-axis faces up, which, needless to say, is interesting: | ||
+ | |||
+ | <asy>import three; | ||
+ | |||
+ | currentprojection = orthographic(-1,-2,1); | ||
+ | |||
+ | draw((0,0,0)--X, EndArrow3); | ||
+ | draw((0,0,0)--Y, EndArrow3); | ||
+ | draw((0,0,0)--Z, EndArrow3); | ||
+ | label("$x$", X, X); | ||
+ | label("$y$", Y, Y); | ||
+ | label("$z$", Z, Z); | ||
+ | </asy> | ||
+ | |||
+ | In any case, use currentprojection lightly. Asymptote will try to find the best projection for you, so only use it if you want to see your drawing from a different angle, or if you want to change the mode (e.g. perspective to orthographic). | ||
+ | |||
+ | [[Category: Asymptote]] |
Latest revision as of 19:22, 15 December 2020
Current projection
Suppose you are floating in a three-dimensional universe that extends infinitely in each direction. A bright source of light illuminates the scene. You can move freely around this universe, enabling you to see everything in different perspectives.
At this point, there is a giant grid with a sphere on it. From your point of view, it looks like this:
This is what perspective projection is like. Basically, it is as if you were floating in this universe looking at the object with your own eyes. Closer objects are larger than farther objects, parallel lines converge, and, most importantly, I don't get dizzy.
Now, suppose you wore glasses that nuked your sense of perspective and replaced it with a different world, a world where parallel lines stay parallel and closer objects are of the same size as farther objects. This is what you'd see:
This, my friends, is orthographic projection. It's not natural, but it's very useful when you want everything to be at the same scale, regardless of distance.
So now that we've figured out exactly what the heck are perspective and orthogonal projection, let's find out how to do it in Asymptote.
Declaring projection is easy:
// Perspective currentprojection = perspective(camera=(x,y,z)); // Orthographic currentprojection = orthographic(camera=(x,y,z));
Here, camera=(x,y,z) states the position of the camera, whose viewpoint the reader sees the drawing from. In our hypothetical universe, this would be the exact same thing as defining your position. Asymptote dictates that the -axis faces up, which, needless to say, is interesting:
In any case, use currentprojection lightly. Asymptote will try to find the best projection for you, so only use it if you want to see your drawing from a different angle, or if you want to change the mode (e.g. perspective to orthographic).