Message Boards Message Boards

1
|
2499 Views
|
6 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Built-in function for projecting a point in 3D to 2D?

Posted 1 year ago

I want to use Mathematica to calculate the projection of a point in 3d to a canvas in 2d.

I need to convert the point

(x,y,z)

to

enter image description here

where k (positive) is the distance between the viewer and the canvas.

Is there any built in function that does it?

POSTED BY: Ehud Behar
6 Replies
Posted 1 year ago

You can achieve this with LinearFractionalTransform:

LinearFractionalTransform[
  {{{1, 0, 0},
    {0, 1, 0}},
   {0, 0},
   {0, 0, 1/k},
   1}][{x, y, z}]

(* {x/(1 + z/k), y/(1 + z/k)} *)

Is it worth the hassle is another question...

This corresponds to the following TransformationFunction:

enter image description here

POSTED BY: Jari Kirma
Posted 1 year ago

Thanks! I actually came across the various TransformationFunctions but this one slipped away. That's what I was looking for.

POSTED BY: Ehud Behar
Posted 1 year ago

I don't know what constitutes "better" for you. I'm not sure why operating on a point as you described is a problem. If I were to do it, I'd probably define a function like this:

MyProjection[k_, {x_, y_, z_}] := {x/(z/k + 1), y/(z/k + 1)}

Or maybe:

MyProjection[k_][{x_, y_, z_}] := {x/(z/k + 1), y/(z/k + 1)}

to make currying easier.

POSTED BY: Eric Rimbey
Posted 1 year ago

Never seen this way of building a function (f[x_][y_]):=...`).

Thanks for a lot for your help.

POSTED BY: Ehud Behar
Posted 1 year ago

Is it critical that it be a built in function, or are you just asking more generally how to do this?

POSTED BY: Eric Rimbey
Posted 1 year ago

Thanks for your reply. I would prefer a built in function. If you can come up with a better solution than just working with pt[[1]]/(pt[[3]]/k+1) etc. I would be very glad to learn it.

POSTED BY: Ehud Behar
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract