Title: [ENH]: Specify a custom focal length / FOV for the 3d camera · Issue #22035 · matplotlib/matplotlib · GitHub
Open Graph Title: [ENH]: Specify a custom focal length / FOV for the 3d camera · Issue #22035 · matplotlib/matplotlib
X Title: [ENH]: Specify a custom focal length / FOV for the 3d camera · Issue #22035 · matplotlib/matplotlib
Description: Problem I'd like to be able to recreate the perspective-warping effects of changing focal length / FOV of a physical camera in matplotlib, for more fine-tuned camera control and for replicating real-world cameras in software. Proposed so...
Open Graph Description: Problem I'd like to be able to recreate the perspective-warping effects of changing focal length / FOV of a physical camera in matplotlib, for more fine-tuned camera control and for replicating rea...
X Description: Problem I'd like to be able to recreate the perspective-warping effects of changing focal length / FOV of a physical camera in matplotlib, for more fine-tuned camera control and for replicating...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/22035
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[ENH]: Specify a custom focal length / FOV for the 3d camera","articleBody":"### Problem\r\n\r\nI'd like to be able to recreate the perspective-warping effects of changing focal length / FOV of a physical camera in matplotlib, for more fine-tuned camera control and for replicating real-world cameras in software.\r\n\r\n### Proposed solution\r\n\r\nFrom [this slide deck](http://www.terathon.com/gdc07_lengyel.pdf), we see how to generate a projection matrix: \r\n\r\n\r\n[This page has a nice derivation of the matrix](https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/opengl-perspective-projection-matrix).\r\n\r\nThe persp_transformation function in [/lib/mpl_toolkits/mplot3d/proj3d.py](https://github.com/matplotlib/matplotlib/blob/main/lib/mpl_toolkits/mplot3d/proj3d.py) implements this for a fixed focal distance of 1 (equivalent to a FOV of 90 deg):\r\n```\r\ndef persp_transformation(zfront, zback):\r\n a = (zfront+zback)/(zfront-zback)\r\n b = -2*(zfront*zback)/(zfront-zback)\r\n return np.array([[1, 0, 0, 0],\r\n [0, 1, 0, 0],\r\n [0, 0, a, b],\r\n [0, 0, -1, 0]])\r\n```\r\n\r\nIt should not be too hard to update this function to take in a focal length. I think the biggest question is the user interface. ~~The `focal_length` can be taken as fundamental and the current `proj_type` arguments to the Axes3D constructor can be mapped to `focal_length = 1` for `proj_type == 'persp'`. To specify a custom focal length however, what should the user input?~~ \r\n\r\nEdit: I think the easiest thing would be a default `focal_length = None` argument, which can be set by the user but otherwise gets set to 1 if `proj_type == 'persp'`.","author":{"url":"https://github.com/scottshambaugh","@type":"Person","name":"scottshambaugh"},"datePublished":"2021-12-22T05:00:56.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/22035/matplotlib/issues/22035"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:addf596c-19f9-f337-494a-bdbd4f9681e0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9F38:19F60D:2284FC4:2DCF0BB:6A5200F5 |
| html-safe-nonce | 1386efe2d2fa54eed21fdcfcd3c6e8d98da2e41e16da7798dbaf6ebbf97cca35 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RjM4OjE5RjYwRDoyMjg0RkM0OjJEQ0YwQkI6NkE1MjAwRjUiLCJ2aXNpdG9yX2lkIjoiMzAzMTAzMzIwMjI0NjU0OTc0OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 90083f7cf0fec1c234ebf663ca19051695c9874f53bf6514d5ece702df09cc19 |
| hovercard-subject-tag | issue:1086451889 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/22035/issue_layout |
| twitter:image | https://opengraph.githubassets.com/763519bf95f3504a149d2fdb7a91d0fc0c5b761974c59baa87280c9823ca5254/matplotlib/matplotlib/issues/22035 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/763519bf95f3504a149d2fdb7a91d0fc0c5b761974c59baa87280c9823ca5254/matplotlib/matplotlib/issues/22035 |
| og:image:alt | Problem I'd like to be able to recreate the perspective-warping effects of changing focal length / FOV of a physical camera in matplotlib, for more fine-tuned camera control and for replicating rea... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | scottshambaugh |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width