l>A Minimal Ray-Tracer: Rendering straightforward Shapes (Sphere, Cube, Disk, Plane, etc.) (Ray-Plane and Ray-Disk Intersection) Figure 1: ray-plane intersection.

You are watching: A ray that intersects a plane in one point

In this thing we will certainly learn just how to compute the intersection that a ray through a airplane and a disk. We recognize from the class on Geometry that the period (or scalar) product of two vectors which space perpendicular come each various other is constantly equal to 0:

$$A \cdot B = 0$$

Again this is just true if A and also B space perpendicular. A airplane can be identified as a point representing how much the airplane is indigenous the civilization origin and also a typical (defining the orientation of the plane). Let"s call this suggest $$p_0$$ and the plane normal $$n$$. A vector have the right to be computed from any point on the plane by subtracting $$p_0$$ native this suggest which we will call $$p$$. Due to the fact that the vector resulting from this individually lies in the plane, it need to be perpendicular to the plane"s normal, therefore using the property that the dot product of 2 perpendicular vectors is same to 0, we deserve to write (equation 1):

$$(p - p_0) \cdot n = 0$$

Similarly, a ray have the right to be defined using the following parametric type (equation 2):

$$l_0 + l * t = p$$

where $$l_0$$ is the beginning of the ray and also $$l$$ is the ray direction. This only means that we can compute the position of any allude along the beam from the ray"s origin, the direction and the hatchet $$t$$ which is a hopeful real number (which as usual, is the parametric street from the origin of the ray to the suggest of interest follow me the ray). If the ray and also the airplane intersect, then they re-superstructure a point, the allude where the heat intersects the plane. If this allude is $$p$$, we have the right to insert equation 2 in equation 1, and also we get:

$$(l_0 + together * t - p_0) \cdot n = 0$$

What we room interested in here, is come compute a worth for $$t$$ indigenous which we deserve to compute the position of this intersection point using the ray parametric equation. Addressing for $$t$$ we get:

$$\beginarrayll * t \cdot n + (l_0 - p_o) \cdot n = 0\\t = -\dfrac(l_0-p_0)\cdot nl \cdot n = \dfrac(p_0 - l_0) \cdot nl \cdot n\endarray$$

Note that the airplane and the ray space parallel as soon as the denominator (the hatchet $$l \cdot n$$ gets close come 0. One of two people the plane and the ray perfectly coincide in which situation there is one infinity of remedies or the ray is away from the airplane in which situation there is no intersection. Generally in a C++ implementation, when the denominator is lower than a very tiny value, we merely return false (no intersection to be found).

bool intersectPlane(const Vec3f &n, const Vec3f &p0, const Vec3f &l0, const Vec3f &l, to rise &t) // assuming vectors room all normalized float denom = dotProduct(n, l); if (denom > 1e-6) Vec3f p0l0 = p0 - l0; t = dotProduct(p0l0, n) / denom; return (t >= 0); return false; Figure 2: ray-disk intersection.

See more: Me So Horney Me Love You Long Time Lyrics, Me So Horny Lyrics

The ray-disk intersection regimen is an extremely simple. A disk is generally defined by a position (the disk center"s position), a normal and also a radius. An initial we have the right to test if the ray intersects the airplane in i m sorry lies the disk. Because that the ray-plane intersection step, we deserve to simply usage the code we have arisen for the ray-plane intersection test. If the beam intersects this plane, every we have to do is to compute the intersection point, climate compute the street from this point to this disk"s center. If this distance is reduced or equal to the disc radius, then the beam intersects the disk. Keep in mind that together an optimisation, you can test the square that the distance versus the square that the disk"s radius. The square distance deserve to be computed indigenous the period product that this vector (v in the code) with itself. Technically, computing the street would require to take the square root of this dot product. Yet we can also test the an outcome of this period product directly versus the square that the radius (which is generally precomputed) to avoid using a square root operation which is expensive.

bool intersectDisk(const Vec3f &n, const Vec3f &p0, const float &radius, const Vec3f &l0, const Vec3 &l){ rise t = 0; if (intersectPlane(n, p0, l0, l, t)) { Vec3f ns = l0 + l * t; Vec3f v = ns - p0; to rise d2 = dot(v, v); return (sqrtf(d2)