Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draw "2.5-dimensional" vector graphics #529

Open
charlesstaats opened this issue Feb 22, 2025 · 0 comments
Open

Draw "2.5-dimensional" vector graphics #529

charlesstaats opened this issue Feb 22, 2025 · 0 comments

Comments

@charlesstaats
Copy link
Contributor

This will take a while and may never come to fruition, but I think a lot of asy users from the TeX world would appreciate it.

The current experimental "render=0" mode has some pretty severe limitations regarding things like hidden surface removal and drawing surfaces without a visible mesh / grid. Realistically, I don't think we can have surfaces with complex shading and no grid. This seems to be a limitation of pdf viewers: just because two shaded regions should, mathematically, meet exactly, does not mean they will -- many pdf viewers will leave a gap between them. And I don't think we're going to find a decent workaround for this.

However, many users are interested in drawing 3d diagrams without complex shading. Some examples:

from https://tex.stackexchange.com/a/135438/484 (author: me):

computer-generated line drawing of a torus with a helix wrapped around it

from https://tex.stackexchange.com/a/736786/484 (author: Theo H):

sphere with several line segments, circles, and angles between these, as well as angle to a radius of the sphere

The basic approach to such a rendering mode would involve

  • dividing paths and surfaces into pieces based on where they intersect other surfaces (or self-intersect)
  • dividing surfaces based on where they are tangent to the camera ray (i.e., where they "fold" back behind themselves)
  • further dividing paths and surfaces wherever, in the 2d projection, they cross behind the boundaries of surfaces that are closer to the camera
  • apply a painter's algorithm to draw (resp shade) 2d projections of the resulting paths (resp surface regions) starting with the most distant

The purpose of the first three steps is to ensure that, whenever two path or surface regions have their projections intersect, it is well defined which of them is closer to the camera. (The ordering can be reconstructed by finding an intersection point in the 2d projection, turning that point into a ray from the camera, finding points in which that ray intersects each of the two objects, and calculating which of the two objects has an intersection point closer to the camera.)

Even a fairly minimal version of this would require a number of more basic features, such as the following:

  • Reliably fast intersection between a path3 and a surface. (The current algorithm is not reliably fast and sometimes results in too many intersection points; see Intersecting a patch with a path3 can be extremely slow #6.)
  • Intersecting two surfaces to produce a path3, as well as a path in the coordinate space (whatever that means) of each surface.
  • A way determine the boundary of a surface. Ideally, this could be deduced from the bezier patches if we added data about neighboring patches. The neighbor data will also come in handy when we need to determine, for instance, whether the surface has any self-intersections.

This plan may never come to fruition, but I wanted to at least set it down. I'm reasonably confident that, given enough time and determination, it could be done. I'm less confident that the surface-surface intersections could be computed in a reasonable amount of time, but I think it could be worth trying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant