Repository navigation
Orthographic projection for mplot3d - #8326
Conversation
dstansby
left a comment
There was a problem hiding this comment.
Neat little new feature! Just a couple of implementation changes I've suggested.
| *elev* Elevation viewing angle (default 30) | ||
| *zscale* [%(scale)s] | ||
| *sharez* Other axes to share z-limits with | ||
| *persp* Perspective projection (default True) |
There was a problem hiding this comment.
I think it would be better to have a proj argument instead, which (at the moment) could take either 'persp or ortho values, and default to persp.
There was a problem hiding this comment.
I agree. In that case, should I provide the setter set_proj? There is a get_proj which has different meaning.
There was a problem hiding this comment.
Maybe use projection instead of proj to avoid breaking get_proj?
I think a better alternative would be to rename the current get_proj to get_proj_matrix - might be worth seeing what other devs think about that.
| fig = plt.figure() | ||
| ax = fig.gca(projection='3d') | ||
| ax.set_persp(False) | ||
| ax.set_xlabel('X') |
There was a problem hiding this comment.
This test doesn't really need any text, so could the label lines be removed.
- renamed persp to proj - renamed get_proj to get_proj_matrix - add test for ortho_projection
|
I am not too sure about this. The name |
| R = np.array([100, 100, 100]) | ||
| V = np.array([0, 0, 1]) | ||
| viewM = proj3d.view_transformation(E, R, V) | ||
| perspM = proj3d.persp_transformation(100, -100) |
There was a problem hiding this comment.
I am not sure about this either. This seems to assume zfront and zback refer to the coordinates on the camera's Z axis (which is backwards), but judging from other places where it's called, they seem to be equivalent to near / far plane.
https://github.com/matplotlib/matplotlib/blob/master/lib/mpl_toolkits/mplot3d/axes3d.py#L1001
There was a problem hiding this comment.
it is entirely possible this test was originally backwards. It came from some commented out code at the bottom of proj3d.py. Seemed like it might have been some debugging code for the original developer. We recently lifted it out of there and put it in as a unit test because it helped us solve a problem.
There was a problem hiding this comment.
Ah, thanks for the clarification. I will leave it as is then.
|
it is unfortunate name choice, but |
| def get_proj(self): | ||
| def set_proj(self, proj): | ||
| """ | ||
| Set the type of projection. |
There was a problem hiding this comment.
Need to expand on this; detail what are the accepted inputs and what they mean.
There was a problem hiding this comment.
Do you think it will be okay if I rename the flag and this setter to proj_type? since I will keep get_proj, using set_proj would cause confusion.
There was a problem hiding this comment.
Yes, I think your new setter/getter can be proj_type. I am a little leery of using the word "type" in a variable name when one is not referring to a type object, but I think it is ok here, especially if it is documented well.
| R = np.array([100, 100, 100]) | ||
| V = np.array([0, 0, 1]) | ||
| viewM = proj3d.view_transformation(E, R, V) | ||
| perspM = proj3d.persp_transformation(100, -100) |
There was a problem hiding this comment.
it is entirely possible this test was originally backwards. It came from some commented out code at the bottom of proj3d.py. Seemed like it might have been some debugging code for the original developer. We recently lifted it out of there and put it in as a unit test because it helped us solve a problem.
| [0,2,0,0], | ||
| [0,0,-2,0], | ||
| [0,0,a,b] | ||
| ]) |
There was a problem hiding this comment.
Can you provide a reference for this formulation? I am not an expert in 3d transforms, but this doesn't match anything I am seeing on the wikipedia page for orthographic projection.
There was a problem hiding this comment.
Sorry, I should have justified it.
This matrix is almost equivalent to the one in the Wikipedia page. Based on persp_transformation, I made these assumptions:
zfrontis the value fornear,leftandbottomzbackforfar,right,top- the X and Y translations are omitted (I guess so the image will always be centered at the origin)
It's a simple derivation from the one from Wikipedia (v1), but since v2 and v1 are equivalent in homogeneous coordinates, I thought the second will look nicer.
There was a problem hiding this comment.
ah, and if I transpose that, it then matches up. Got it. Well, just include some notes about it in comments for some future poor soul.
There was a problem hiding this comment.
Why is this the transpose?
There was a problem hiding this comment.
Because numpy matrix is in row major order?
| self.azim = azim | ||
|
|
||
| def set_proj(self, proj): | ||
| def set_proj_type(self, proj): |
There was a problem hiding this comment.
why didn't you rename the argument name as well?
There was a problem hiding this comment.
Thanks for pointing out, I just renamed the argument.
|
This looks great. The only thing left to do is to add an entry to the what's new page: There should be some notes in doc/users/whats_new/ |
|
I am new to numpydoc. The file I created seems to compile, but I had trouble generating everything under |
|
we build the docs as part of our test suite. If it builds there, that should be sufficient. |
|
It would be nice to get more documentation for this feature, especially prose and graphics showing when this feature makes a significant improvement. However, that can be done in a separate PR. |
|
@dstansby , I take it that your concerns have been addressed? |
|
Sorry, this one dropped off my radar, looks like everything I mentioned has
been fixed so feel free to dismiss my review.
On 7 Apr 2017 4:11 pm, "Benjamin Root" <[email protected]> wrote:
@dstansby <https://github.com/dstansby> , I take it that your concerns have
been addressed?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#8326 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AF6RfH9KrjeDvP4Bw0nKEBxdhjyJWwnWks5rtlIwgaJpZM4MhS7y>
.
|
|
Thanks to everybody! |
Fixes #537
ortho_transformation()in proj3dperspand a setterset_persp()Here is a simple demo: