POV-Ray : Newsgroups : povray.advanced-users : Converting 2D screen coordinates to 3D : Re: Converting 2D screen coordinates to 3D Server Time26 Mar 2023 21:53:19 EDT (-0400)
 Re: Converting 2D screen coordinates to 3D
 From: Bald Eagle Date: 6 Feb 2023 13:25:00 Message:
```
{
"@context": "https://schema.org",
"@type": "DiscussionForumPosting",
"@id": "#web.63e1453eef540dd71f9dae3025979125%40news.povray.org",
"headline": "Re: Converting 2D screen coordinates to 3D",
"dateCreated": "2023-02-06T18:25:00+00:00",
"datePublished": "2023-02-06T18:25:00+00:00",
"author": {
"@type": "Person",
"name": "Bald Eagle"
}
}
"Kenneth" <kdw### [at] gmailcom> wrote:
> A couple of initial (naive?) questions, to help me better-visualize the details:
> >
> > Assume an orthographic camera.
> > Let's say that I have a line segment extending from the top left of
> > an image to the lower right.
>
> Is that initial line an actual object in the 3-D scene that appears to extend
> from corner to corner, or is it a line only in flat 2-D screen space (like
> Screen.inc would typically produce, for example)? I'm guessing it's a 3-D
> object, extending into the scene.

That initial line is indeed an axis of the object, which would extend forward
and backward from the image plane if it were an actual 3D object.

> > If I draw a line perpendicular to this, then I can use this
> > new line as an axis for rotation.
>
> Perpendicular to it in x/y screen space, or pointing 'out' from the middle of
> the initial line segment directly into the camera? Or maybe pointing somewhere
> else in 3-D space? Sorry, this one is hard to visualize.

Making the line perpendicular in screen space.  Then when the z-buffer line gets
rotated it remains "in place"/in-line with where it already is, just with +/-
z-components in the vectors of the now-rotated endpoints.

> > If I rotate a copy of the line segment around this axis, it should visually
> > remain in line with the original line segment, but the ends would appear to
> > contract.
>
> I can sort of 'see' this...depending on whether or not I understand the initial
> stuff.

Image of work so far attached.   It's halfway there, though I'm guessing at
magic rotation angle numbers and just flying by the seat of my pants through
intuition.

Apparently there's a much better way to do this that's used in multiple view
geometry in computer vision, but it uses QR decomposition and SVD, among other
matrix operations.   There are Matlab libraries to do some of this, but it would
of course be preferable to be able to do this ourselves in SDL/source.

I should probably see if I can find a copy of Hartley and Zisserman, or the more
modern text that has supplanted it - Photogrammetric Computer Vision:

https://users.cecs.anu.edu.au/~hartley/Papers/CVPR99-tutorial/tut_4up.pdf

https://mathematica.stackexchange.com/questions/9244/solve-system-of-equations-related-to-perspective-projection

https://math.stackexchange.com/questions/242661/finding-a-3d-transformation-matrix-based-on-the-2d-coordinates

https://math.stackexchange.com/questions/455128/how-to-find-an-all-in-one-2d-to-3d-transformation-matrix-for-perspectiv
e-project
```

Attachments: