Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] - [Matrix1Utils] Intersections of self-intersecting tori

Author
Message
Diggsey
17
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 9th May 2012 23:14 Edited at: 9th May 2012 23:29
This code calculates and displays the intersection lines of three self-intersecting tori:





As well as producing some nice colourful curves, the results are actually very useful. I originally came to write this because I was trying to calculate the position in space of a video camera based on three known points in its field of view.

This problem turns out to be very complicated, but after much doing of maths I managed to work out that it was equivalent to the points of intersection of three tori.

Unfortunately calculating the points where three tori intersect is also very difficult (requires solving three simultaneous non-linear equations) but I eventually found this iterative numerical solution which gives very good results (as you can see).

Also, the vector functions there are very useful on their own.

Maths stuff:
The original problem was to use three points whose 2d positions are known on the image produced by a camera to work out the location of that camera.

The first problem is that the locations of the points are not only affected by the camera's position, but also by its rotating. The rotation and position each have 3 components giving a total 6 unknowns to be solved simultaneously based on 6 input values (3 X,Y pairs), which is not very practical.

To get around this I found a way to separate the position and rotation information, simplifying the problem to 3 unknowns: work out the angle between each pair of points (this is approximately proportional to the distance between each pair, but can be worked out exactly without much difficulty).

However the camera is rotated, the angle between each pair of points will not change. Now the problem is how to convert the 3 angles into a position.

In 2d, the set of points which make a fixed angle with two other points always make a circle: inscribed angle theorem. The special case of this which is most well known is that if you pick any point on a semicircle and draw lines to the end points of that semicircle, the angle between them is always 90 degress.

It turns out to be very simple to extend this to 3d: instead of a circle being produced, a circle rotated through another circle is produced (a torus). Each pair of points and the angle between them produces a torus, so now the problem is to find a point that exists on all 3 tori (ie. their intersection).

There's no simple way to do this, but it turns out to be fairly easy to project a random point in space onto the nearest point on a torus, (see the function "vec3_project_onto_torus"), so if points are picked at random and then repeatedly projected onto each torus, they will very quickly end up at the points where they intersect.

Displaying a number of discrete points is not particularly interesting though, so the program instead draws the intersection between each pair of tori in different colours, and the points where those three intersect are the solutions.

[b]

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-04-19 22:02:41
Your offset time is: 2024-04-19 22:02:41