Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[ENH]: Specify a custom focal length / FOV for the 3d camera #22035

Closed
@scottshambaugh

Description

@scottshambaugh

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 solution

Fromthis slide deck, we see how to generate a projection matrix:
image

This page has a nice derivation of the matrix.

The persp_transformation function in/lib/mpl_toolkits/mplot3d/proj3d.py implements this for a fixed focal distance of 1 (equivalent to a FOV of 90 deg):

def persp_transformation(zfront, zback):    a = (zfront+zback)/(zfront-zback)    b = -2*(zfront*zback)/(zfront-zback)    return np.array([[1, 0, 0, 0],                     [0, 1, 0, 0],                     [0, 0, a, b],                     [0, 0, -1, 0]])

It should not be too hard to update this function to take in a focal length. I think the biggest question is the user interface.Thefocal_length can be taken as fundamental and the currentproj_type arguments to the Axes3D constructor can be mapped tofocal_length = 1 forproj_type == 'persp'. To specify a custom focal length however, what should the user input?

Edit: I think the easiest thing would be a defaultfocal_length = None argument, which can be set by the user but otherwise gets set to 1 ifproj_type == 'persp'.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp