3D graphics: finding optimal view of a scene with constraints

In summary: The rotation matrix will transform the model to camera space, and the camera position will be relative to the origin of rotation (in model space). The front plane distance from the camera and the rear plane distance from the camera are also variables.To solve for the rotation matrix, you first need to calculate the constants for constraint 1. The orthoscopic flag tells you whether or not to consider mirrored views when solving for the rotation matrix. If the orthoscopic flag is non-zero, then mirrored views must be taken into account. If the orthoscopic flag is zero, then the rotation matrix will
  • #1
Polverone
2
0
Pardon me if this should go elsewhere, but it seems like a problem with a linear algebra solution.

I have a series of PDB files from a molecular dynamics simulation of modified DNA strands. I use the program Pymol (http://www.pymol.org) to visualize them as a "movie." But now I want to make a real movie - that is, create a series of raster images that I can encode as a video file. I know how to do that with Pymol, by loading a PDB file, adjusting viewing parameters, and rendering/saving a raster image (repeat x1000). The problem is that the molecule shifts and twists over time, so that the region I want to view becomes hard to see unless I make adjustments by rotating the view. When I'm making raster frames I cannot use the interactive mouse controls like I would when viewing on my desktop machine; I must programmatically determine the compensation-rotations to keep my region of interest unobscured and level.

My idea is to pick two carbon atoms from opposite sides of the strand but located on the same level and two on the same side but located on different levels like so:
http://www.sciencemadness.org/scipics/shot1.png (front)
http://www.sciencemadness.org/scipics/shot2.png (top)
http://www.sciencemadness.org/scipics/shot3.png (side)

Imagine a measurement of the vertical distance between the two left green points or the two right green points (I will just choose left or right and stick with it, ultimately), as seen by the viewing camera. I want to rotate the model so that this vertical distance is maximized (constraint 1). Now imagine a measurement of the horizontal distance between the two magenta points as seen by the viewing camera. I want to maximize this distance (constraint 2) with rotation while still honoring constraint 1. I think this constraint should naturally produce a line that appears perfectly horizontal, but if doesn't, consider "the line must appear perfectly horizontal" as an additional constraint. There are multiple "best" views possible, since mirrored views are going to be the same, but the chosen view should be the best view that differs the least from the best view of the previous frame (constraint 3). This is a long-winded way of saying that I want to always be orienting the model so that I have a clear head-on view of these 3 base pairs.

Here's what I have to work with in modifying the view:
Contents of the view matrix
0 - 8 = 3x3 rotation matrix which transforms model to camera space
9 - 11 = camera position (in model space and relative to the origin of rotation)
12 - 14 = origin of rotation (in model space)
15 = front plane distance from the camera
16 = rear plane distance from the camera
17 = orthoscopic flag

Suppose that everything but the rotation matrix will remain static over the course of the animation, but any of these values can be retrieved. I know that these constraints *can* be satisfied, but I'm at a loss how to go about it. I've done only a little with 3D graphics before, and the other systems I used let me use quaternions or Euler angles to control rotations. Here I just have a matrix. I've spent some time reading Computer Graphics: Principles and Practice as well as the comp.graphics.algorithms FAQ, and neither got me very far. I have a feeling that this would be a pretty simple problem for someone well-versed in linear algebra or 3D graphics, but I am not yet that someone and I need to make these animations before next week :eek:

I would very much appreciate it if someone can help me with this, keeping in mind that I did once study linear algebra but it was a while ago, and that I am familiar with most graphics terms (if not the actual implementations).

Edit: I botched one of my constraints. The "maximize vertical distance as seen by the camera" constraint doesn't work because of the twisting of the strand. This constraint will lead to terrible viewing angles. Maybe I should have said "as seen by an orthographic camera" or somesuch... along with additional constraints on what sort of rotation is allowed? Meh, this is even trickier than I thought. I always want to view this 3 base pair region head-on, however that can be stated formally. Any suggestions for dealing with my problem are welcome, even if they're "download this great molecular visualization program BlahViz, it'll do what you want out of the box."
 
Last edited:
Physics news on Phys.org
  • #2
Let me try some rambling here: hopefully some of this will help you.

If you want to orient the green points so they're vertical, one algorithm is this:

Find the [X,Y,Z] direction vector which points from Green point 1 (GP1) to GP2. We'll call this GP12. Normalize this vector. Then find the rotation matrix to turn GP12 into [0,0,1]. Apply that rotation matrix to all of the points. That will rotate your entire molecule and you'll have the greens aligned N-S, and the screen distance between them will be maximized.

For the two magenta points (direction vector called MP12), you now will have a problem. If a constraint is that MP12 must appear horizontal, then GP12 (although keeping it N-S is still possible) cannot be maximized as viewed from the screen. This is, of course, assuming that MP12 isn't exactly horizontal. If you rotate GP12 about an arbitrary vector normal to both the viewscreen and GP12, then you could get the magentas to line up, but the magnitude of GP12 as viewed from the screen will decrease.

I have an idea how to do what you need. I took a geometry for computer graphics course last semester, but unfortunately, it was the class which I spent the least time on, and I can only really remember the concepts... not the implementation. Additionally, I don't know how you would be able to import the data into the software you're using.

Take a look http://www.math.umd.edu/~gah/Pages/Math431Lecturespg.html It is the lecture notes for the class I took. It's got a link to download MathReader which is the free viewer for Mathematica. Unfortunately, you won't be able to play around with any of the stuff, but you will at least see the notes.

Vector Rotations about a non-origin point are covered in section 1.3

Viewing angle is covered somewhere in chapter 4.

I'm afraid that this will probably be too nitty-gritty and less "how do I do it" for you at this point.
 
Last edited by a moderator:
  • #3
enigma said:
Let me try some rambling here: hopefully some of this will help you.

If you want to orient the green points so they're vertical, one algorithm is this:

Find the [X,Y,Z] direction vector which points from Green point 1 (GP1) to GP2. We'll call this GP12. Normalize this vector. Then find the rotation matrix to turn GP12 into [0,0,1]. Apply that rotation matrix to all of the points. That will rotate your entire molecule and you'll have the greens aligned N-S, and the screen distance between them will be maximized.

For the two magenta points (direction vector called MP12), you now will have a problem. If a constraint is that MP12 must appear horizontal, then GP12 (although keeping it N-S is still possible) cannot be maximized as viewed from the screen. This is, of course, assuming that MP12 isn't exactly horizontal. If you rotate GP12 about an arbitrary vector normal to both the viewscreen and GP12, then you could get the magentas to line up, but the magnitude of GP12 as viewed from the screen will decrease.

I have an idea how to do what you need. I took a geometry for computer graphics course last semester, but unfortunately, it was the class which I spent the least time on, and I can only really remember the concepts... not the implementation. Additionally, I don't know how you would be able to import the data into the software you're using.
Thanks for trying to help with my problem. All my geometry data is available to me as x,y,z triples (there's connectivity information too, but I just care about the points). All I want is to automatically rotate the model so that I always have a level, head-on view of the region of interest (which consists of the 3 base pairs I showed in my screenshots). It seems like somebody must have solved this problem before with an algorithm or decent heuristic, but I can't recall having come across such info in my readings on graphics and I'm having a hard time figuring it out now.
 
  • #4
Recently, I've been using VPython http://vpython.org/ for my 3D-visualization needs.

I wonder if VPython can satisfactorily render your dataset for you. You can easily create an animation by moving the camera position or changing the center of the view. (See http://vpython.org/webdoc/visual/display.html )

If you must render in your software, maybe VPython can interface with your program and "steer the camera". VPython supports vector and matrix calculations (via Numeric) and may help simplify your calculations.

Here are some other tools that may be of interest
http://vrmlworks.crispen.org/tools.html
 
Last edited by a moderator:

1. What is 3D graphics?

3D graphics refers to the creation, manipulation, and rendering of three-dimensional objects and scenes on a computer. It involves using mathematical algorithms and techniques to simulate the appearance and behavior of real-world objects in a virtual environment.

2. How do you find the optimal view of a scene in 3D graphics?

Finding the optimal view of a scene in 3D graphics involves considering various factors such as the position and orientation of the camera, the objects in the scene, and any constraints or limitations. This can be achieved through techniques such as camera placement algorithms, view frustum culling, and occlusion culling.

3. What are constraints in 3D graphics?

Constraints in 3D graphics refer to any limitations or restrictions that must be taken into account when creating or rendering a scene. These can include technical constraints such as hardware limitations or design constraints such as artistic preferences.

4. How do constraints affect the optimal view of a 3D scene?

Constraints can affect the optimal view of a 3D scene by limiting the possible camera positions and orientations, as well as the objects and features that can be included in the scene. The optimal view must balance these constraints to create a visually appealing and technically feasible view of the scene.

5. Can algorithms be used to find the optimal view of a 3D scene with constraints?

Yes, algorithms can be used to find the optimal view of a 3D scene with constraints. These algorithms can take into account various factors such as the constraints, camera position, and object placement to generate the most suitable view of the scene. However, the final decision must also consider the artistic vision and preferences of the designer or artist.

Similar threads

  • Linear and Abstract Algebra
Replies
6
Views
4K
  • Mechanical Engineering
Replies
3
Views
1K
  • Special and General Relativity
Replies
25
Views
880
  • Astronomy and Astrophysics
Replies
19
Views
4K
  • Introductory Physics Homework Help
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
  • General Engineering
Replies
17
Views
2K
  • Differential Geometry
Replies
1
Views
2K
Replies
10
Views
1K
  • Other Physics Topics
Replies
1
Views
1K
Back
Top