How to plot a 3D point on a VR (virtual reality) image

I'm trying to understand the formula to go from a 3D point (x, y, z) in the world to a virtual representation on a 2D image.

I'm using this page as an example:

enter image description here

How do I get the (a, b) position from the real (x, y, z) location of the ball?

If you inspect the page, there is a lot of interesting information:

  • the page uses this 3D library

  • the balls are represented by (x,y,0) locations such as for the "VR camera [1-4]" views:

    this.graphs['vr-2'].setData( {"names":["PLAYER A","PLAYER B"],"sets":[0,0],"data":{"1.1.1":{
    ],[]],"strikes":[[],[]]},}} );
  • the middle of the net seems to be (0, 0, 0)

  • In the example above, the four balls are:

    -11.8872, 5.4864, 0 (the ball on the tennis double line)
    0, 0, 0 (the ball in the middle of the net)
    6.4008, 0, 0 (the ball at the T serve line)
    -11.8872,-5.4864, 0  (the ball on the other tennis double line)
  • the file projection.js has the following content:


I think that my question boils down to how do I use the data in projection.js to calculate the (a, b) position from the (x, y, z) location? Note that I'm trying to get the formula and I'm not so interested by the javascript library as I will have to do an implementation with different tools.

EDIT #1:

The view data seems to include: height, width, y (yaw), p (pan), tx, ty, tz (camera position), r (roll), ar (???, always 1), fl (focal length???), cx, cy (center on image????).

This page gives a formula but it doesn't include the yaw:

    procedure 3Dto2D (x, y, z, pan, centre, position)

    x = x + position.x
    y = y + position.y
    z = z + position.z

    new.x = x*cos(pan.x) - z*sin(pan.x)
    new.z = x*sin(pan.x) + z*cos(pan.x)
    new.y = y*cos(pan.y) - new.z*sin(pan.y)
    z = new.y*cos(pan.y) - new.z*sin(pan.y)
    x = new.x*cos(pan.z) - new.y*sin(pan.z)
    y = new.x*sin(pan.z) + new.y*cos(pan.z)

    if z > 0 then
        screen.x = x / z * zoom + centre.x
        screen.y = y / z * zoom + centre.y
    end if

If I consider the ball on the tennis double line for the VR Camera 2, I have the following information:

REAL WORLD POSITION (from html source)
X:  -11.8872
Y:  -5.4864
Y:  0.0

VR CAMERA 2 INFORMATION (from javascript projection.js)
height: 290
width:  578
y:  2.14571658875068
p:  -1.86560642719269
tx: 27.0765197103578
ty: 16.2179742216193
tz: 10.4983372879028
r:  0.0
ar: 1.0
fl: 445.122161865234
cx: 289
cy: 145

2D LOCATION (from live inspection of page in browser inspector)
A:  121.9715646498276
B:  193.3313740587937

What is the function (A, B) = f(X, Y, Z, height, width, y, p, tx, ty, tz, r, ar, fl, cx, cy)?



Yaw is calculated:

x_new = x * cos (yaw) - y * sin (yaw)
y_new = x * sin (yaw) + y * cos (yaw)


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.