Hey everyone,
I am de co-founder of watchX, please see:
https://arikovani.com/en/projects/watchx-kodlanabilir-akilli-saat/detail
I wondered whether I can make a script that shows points and lines in the 3D space or not. Since I am a mechanical engineer, I am not that good with coding, but I am really good with analytic geometry and trigonometry. So, I have decided to do it.
First I need to define my camera setup and 3D space. We are looking at 3D images in our computers in a 2D projected perspective. What I mean is that the 3D parameters are projected to our display with respect to our camera properties such as distance from the object, orientation, field of view etc… That’s why defining the camera is important.
And my approach is something like a two planar sphere model. I may sound dumb but I promise it will make sense… We have a 2D coordinate system in our displays. Each pixel is defined with X and Y coordinates. Therefore I need to evaluate where does a point in 3D space projects at the screen. This means I need to do two sets of calculations for each horizontal and vertical data of the projection.
Here you can see my idea of two planes intersecting and showing the field of view of the camera.
From this point on, I will only focus on the explanation in vertical space. The horizontal space will be the same. Here you can see a phenomenon that I named as the viewing circle. This circle represents the vertical 64 pixels of watchX display. The origin point stays right in the middle of the arc. Therefore the vertical position of the origin will be right in the middle too.
Here you can see that a smaller object closer to the camera can block the bigger object which is further away.
If I want to represent a point Pxyz, I have to calculate the relation between Archlength A and B. This relation will result in the vertical position of the point Pxyz at watchX display.
In the next section, I will try to calculate the viewing circle radius (distance between camera and point) Archlength A and B. Than I will try to do the same for the horizontal space. After successfully doing these I will try to represent point clouds in 3D environment and I will try to make wireframe models in 3D.
My final goal is to manipulate the camera with the help of IMU and have a look at the objects in different angles.
I have tried to derive the projection formulas for my theory in my first message. It required to make complex calculations for arclength formulas. Therefore I decided to change my approach a bit and come up with a line based model. The calculations in this form is much more simple than the previous approach.
You can see that I made a wrong assumption in the first post. The “Field of View” data for vertical and horizontal calculations are different because the aspect ratio of the display is 2:1
You can see that the projection formulas for X and Y on display for a point defined in the space are marked as green.
In the next post, I will put a code together to visualize a pyramid and manipulate it’s position to see the perspective effects.
And here is our first 3D image!A pyramid made of 4 points, 4 polygons and 6 lines.
Let’s have a look at the code. Here is our main code frame:
We have defined the camera position, field of view, object position at first. Then, we are running the 3D projection formulas, Pyramid calculation and drawing line functions. I have decided to separate the main code into subfunctions so that the code will look tidy.
We have 4 different points to define the pyramid, xyz for every point means that we have to define 12 different parameters for 4 points. And if we want to manipulate the object, we have to redefine the points again. I decided to put all of these points into a function and derive them from the origin point of the object. You can see that I have defined ObjXYZ already. Here is the function for point calculation:
Here we are calculating the X and Y coordinates of every point projected on the watchX display. These formulas are derived in the previous post with respect to my 3D Projection theory.
This function draws lines between the points to construct a wireframe representation of the pyramid: (I did not use the draw pixels function but it can be used as well.)
Next, I will move the object in space so that we can see the perspective and realize the object in 3D.
And you can download the current scratch code from
https://drive.google.com/file/d/1WBFF-AMDPEk5EP5ZqpxADIS2ZaFff73K/view?usp=sharing
For the next phase, I wanted to move the Pyramid in front of the camera in the path of a circle. First we need to define the maths behind;
Here is the latest and greatest video of this crazy work:
Comments
Please log in or sign up to comment.