Difference between revisions of "Asymptote: Crash Course"
(Created page with "== 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 ...") |
m (undoing vandalism) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
At this point, there is a giant grid with a sphere on it. From your point of view, it looks like this: | 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; | import three; | ||
Line 18: | Line 18: | ||
draw(scale(2,2,2)*unitsphere, red); | 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. | 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. | ||
Line 24: | Line 24: | ||
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: | 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; | import three; | ||
Line 37: | Line 37: | ||
draw(scale(2,2,2)*unitsphere, red); | 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. | 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. |
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).