2

I would like to know how to compute rotation components of a rectangle in space according to four given points in a projection plane.

Hard to depict in a single sentence, thus I explain my needs.

I have a 3D world viewed from a static camera (located in <0,0,0>). I have a known rectangular shape (an picture, actually) That I want to place in that space. I only can define points (up to four) in a spherical/rectangular referencial (camera looking at <0°,0°> (sph) or <0,0,1000> (rect)).

I considere the given polygon to be my rectangle shape rotated (rX,rY,rZ). 3 points are supposed to be enough, 4 points should be too constraintfull. I'm not sure for now.

I want to determine rX, rY and rZ, the rectangle rotation about its center.

--- My first attempt at solving this constrint problem was to fix the first point: given spherical coordinates, I "project" this point onto a camera-facing plane at z=1000. Quite easy, this give me a point. Then, the second point is considered to be on the <0,0,0>- segment, which is about an infinity of solution ; but I fix this by knowing the width(w) and height(h) of my rectangle: I then get two solutions for my second point ; one is "in front" of the first point, and the other is "far away"... I now have a edge of my rectangle. Two, in fact.

And from there, I don't know what to do. If in the end I have my four points, I don't have a clue about how to calculate the rotation equivalency...

It's hard to be lost in Mathematics...

To get an idea of the goal of all this: I make photospheres and I want to "insert" in them images. For instance, I got on my photo a TV screen, and I want to place a picture in the screen. I know my screen size (or I can guess it), I know the size of the image I want to place in (actually, it has the same aspect ratio), and I know the four screen corner positions in my space (spherical or euclidian). My software allow my to place an image in the scene and to rotate it as I want. I can zoom it (to give the feeling of depth)... I then can do all this manually, but it is a long try-fail process and never exact. I would like then to be able to type in the screen corner positions, and get the final image place and rotation attributes in a click...

The question in pictures: Images presenting steps of the problem

Note that on the page, I present actual images of my app. I mean I had to manually rotate and scale the picture to get it fits the screen but it is not a photoshop. The parameters found are:

  • Scale: 0.86362
  • rX = 18.9375
  • rY = -12.5875
  • rZ = -0.105881
  • center position: <-9.55, 18.76, 1000>

Note: Rotation is not enought to set the picture up: we need scale and translation. I assume the scale can be found once a first edge is fixed (first two points help determining two solutions as initial constraints, and because I then know edge length and picture width and height, I can deduce scale. But the software is kind and allow me to modify picture width and height: thus the constraint is just to be sure the four points are descripbing a rectangle in space, with is simple to check with vectors. Here, the problem seems to place the fourth point as a valid rectangle corner, and then deduce rotation from that rectangle. About translation, it is the center (diagonal cross) of the points once fixed.

Anoril
  • 101
  • 6
  • So you have four points in a 2D image and you want to position a rectangle in this way that the rectangle's corners are projected onto the corners in the image. Is this accurate? What about the rectangle's translation? A pure rotation will probably not suffice. By "spherical coordinates" you mean a triple `(angle1, angle2, distance)`, don't you? If I did not understand correctly, please add some explaining figures. – Nico Schertler Jul 09 '14 at 11:10
  • Hi, thanks for your reply. I updated the question by adding a link to a page where I take snapshot to help describe the question. 1_ your are quite right in your analysis, but the points are spherical coords I can transform into . 2_ rectangle translation is easily computed by somewhat average the points (to get the shape center). It is part of the problem actually, but I don't think it is the main issue :) 3_ right, a translation and a scaling are necessary. 4_ Spherical coordinates are here special: (longitude/latitude) are given; I fixed the distance. – Anoril Jul 09 '14 at 16:25
  • You probably have better luck on maths StackExchange. You basically want to fit the corners of a rectangle of known size to four rays. I don't have a nice idea for that right now. – Nico Schertler Jul 09 '14 at 17:57
  • Thanks for your time and advices. I'll check this site... – Anoril Jul 09 '14 at 20:11
  • General idea: each point in the projection corresponds to a ray in 3D. If camera is in the origin, points on these rays are multiples of vectors indicating their direction. So you have up to four variables representing the corner points, and can now start to express your conditions in terms of these coordinates. Conditions like right angles, coplanarity, perhaps aspect ratio and/or absolute size. This gives you a set of polynomial equations. Once you have that worked out you can consider how to solve it, but that's really a question for Math SE. – MvG Jul 10 '14 at 00:40
  • you need calculate another angle but [can my answer help you?](http://stackoverflow.com/questions/21643692/calculating-rectangle-3d-coordinate-with-coordinate-its-shadow) – Ivan.s Jan 02 '15 at 21:05
  • Thanks Ivan! I'll read your description in-deep and tell you if it helps me. It looks like so, at first. Regards, – Anoril Jan 05 '15 at 10:14

0 Answers0