In a recent interview with Fox Business, MicroStrategy Executive Chairman Michael Saylor delved into the transformative potential of Bitcoin, positioning it as a pivotal force in the shift from analog to digital capital. Saylor’s insights come at a critical time when the flagship crypto is experiencing renewed interest and growth, highlighting its role in the […]
Several crypto stakeholders have advised Apple, the iPhone maker, to invest in Bitcoin. In a Feb. 16 post on the social media platform X (formerly Twitter), Shapeshift CEO and founder Erik Voorhees urged the technology company to quietly “buy several billion of BTC” and make the top crypto a payment method in its Apple Pay […]
In fields like computer graphics, autonomous vehicle navigation or augmented reality, where immersive experiences are created through the manipulation of 3D environments, a deep understanding of ray intersection and triangulation algorithms empowers data scientists to craft lifelike simulations and interactive virtual worlds.
It also demonstrates that mathematical principles such as pseudo-inverse matrices, least squares optimization, Cramer’s rule or triple scalar products aren’t just theoretical; they’re practical tools for solving real-world problems!
Ray Definition
A Ray starts from a given position and extends infinitely in a given direction, just like a laser beam or a ray of light.
Think of a ray as a one-way street with a fixed starting point, while a line is like a two-way street that stretches endlessly in both directions.
Mathematically, a ray is defined by its origin o and direction d. Since it’s a 1D space, any point along the ray is parametrized by its positive distance (or time) t with respect to the origin.
Ray Intersection
Finding the intersection of two rays r1 and r2 means finding the two parameters t1 and t2, respectively on the first and second ray, that result in the exact same point in space.
An interesting point to note is that we haven’t specified the dimension of the space in which our ray lives. It could be 2D, like a line drawn on a piece of paper, 3D like a laser beam, or even exist in higher dimensions!
Since we’re looking for the values of t1 and t2, let’s concatenate them in a colum vector x. It allows us to vectorize this equation into the canonical linear system Ax=b. For better clarity, there’s an annotation below each term indicating the shape of the matrix or vector, with n being the dimension of the space in which the ray is defined.
N.B. The matrix A is built by concatenating side by side the two directions as column vectors, with the second one being flipped.
Solving Ax=b gives us t1 and t2. However, if either of these parameters is negative, it indicates that the intersection point lies behind one of the ray origins, meaning there’s no intersection between both rays.
The 2D case is the easiest one. Typically, unless they’re exactly parallel, two 2D lines will always converge at a unique common point.
In the image below, r1 and r2 intersect. However, r3 doesn’t intersect any ray because it’s parallel to r2 and meets r1 behind its origin.
2D Ray intersection — Diagram by the author
Solving the linear system
The linear system of equations Ax=b introduced above has n equations and 2 unknowns. Thus, in the 2D case we end up with a system of 2 equations and 2 unknowns, meaning we just have to invert the matrix A.
If the rays are parallel, the matrix A won’t be invertible because its two columns, d1 and -d2, will be collinear.
If you’re not interesting in t1 and t2 and just want to know if there’s an intersection, computing the determinant of A and comparing it against 0 is all you need.
If you’re not interesting in having both t1 and t2, e.g. if you’re looking for the actual 2D position of the intersection point, using Cramer’s rule is a smart trick. It expresses the solution using determinants of A and modified matrices, where one column of A is replaced by b.
Cramer’s rule to identify t1 and t2. Operator |.| is the determinant. Commas separate matrix columns.Photo by Vince Fleming on Unsplash
3D Ray Intersection
Introduction
Unlike the 2D case, it’s highly unlikely for two 3D rays to intersect. For instance, trying to make two laser pointers held by two different people intersect is very challenging.
The linear system Ax=b ends up having 3 equations for 2 unknowns, making it unsolvable unless there’s redundancy within the equations.
Least-Squares
Given the absence of a solution in most cases, the shortest line segment between both rays can be viewed as their intersection. Let’s denote p1 and p2 as the endpoints of this optimal segment, located on r1 and r2 respectively.
3D Ray Intersection — Diagram by the author
Our task now transforms into a least-squares minimization problem. Its formulation is straightforward given that Ax-b already represents the vector between p2 and p1.
It’s a well-known problem. Zeroing the gradient at the optimum gives us the solution using the pseudo-inverse matrix, which is a convenient way to build a square and thus invertible matrix.
Orthogonality
While it appears on the diagram above that the shortest segment is perpendicular to both rays, we have yet to formally prove this, even-though it sounds intuitive.
The zero gradient also implies that the dot product between the segment defined by p1 and p2 and both ray directions d1 and d2 is zero, which proves the orthogonality.
Alternative Linear System
The Least-Squares approach works perfectly fine, but we can also introduce a third unknown variable to make our linear system solvable.
Given that the vectors d1, d2 and p2-p1 constitute an orthogonal basis, we can build an orthogonal frame with o1 as the origin. The points p1 and p2 can then be derived by expressing the local coordinates of o2 with respect to this frame.
We’ll denote the signed length of the segment p2-p1 as δ. Note that the direction of the segment is given by the cross product between both ray directions.
The determinant of a 3×3 matrix can be derived via the scalar triple product, which involves the dot product of one column with the cross product of the other two.
In our case, simplifying the determinant equation is straightforward as the second column is already a cross product. Note that inserting the cross product as the final column would have resulted in the negation of the norm instead.
Solving with Cramer’s rule gives us the optimal t1 and t2 , but also the signed length δ of the shortest segment.
If you love clean equations, you can re-order and swap columns to remove minus signs and make it look better!
Intersection Point
The intersection point can be defined as the middle of the shortest segment, i.e. 0.5(p1+p2).
Conclusion
I hope you enjoyed reading this article and that it gave you more insights on how to intersect 2D or 3D rays!
Today, we are excited to announce that Code Llama foundation models, developed by Meta, are available for customers through Amazon SageMaker JumpStart to deploy with one click for running inference. Code Llama is a state-of-the-art large language model (LLM) capable of generating code and natural language about code from both code and natural language prompts. […]
Three years after Apple kicked Epic Games off the App Store for breaking terms of business, it has allowed the firm to return with a developer account — and “Fortnite” — for use within the EU.
Still from the Epic Games-produced ad criticizing Apple for being like the book a1984
Apple cancelled the Epic Games developer account in August 2020, after the gaming firm violated App Store agreements in what turned out to be the start of a years-old legal battle. Apple wanted to remove all of Epic’s developer accounts, but a judge insisted that removing its Unreal Engine account would have harmful effects on its countless users.
Epic had asked Apple to allow it a developer account when it wanted to sell apps in Korea. Apple refused. The company said that it would only allow Epic Games back when it “agree[s] to play by the same rules as everyone else.”
Numerous Apple MacBook Air configurations with an upgrade to 16GB or 24GB of memory are $200 off at B&H Photo.
Get a MacBook Air with 16GB RAM for $1,099.
B&H’s Friday sale features some of 2024’s lowest prices on upgraded M2 MacBook Air 13-inch models. Whether you’re looking for extra memory or additional storage, triple-digit savings are in effect in addition to free expedited shipping within the contiguous U.S.
Get the Travel Hacker Bundle ft. Rosetta Stone this Presidents’ Day
Originally appeared here:
Get the Travel Hacker Bundle ft. Rosetta Stone this Presidents’ Day
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie
Duration
Description
cookielawinfo-checkbox-analytics
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional
11 months
The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy
11 months
The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.