{"id":1516,"date":"2020-07-03T02:11:45","date_gmt":"2020-07-03T02:11:45","guid":{"rendered":"http:\/\/lousodrome.net\/blog\/light\/?p=1516"},"modified":"2020-09-20T18:28:38","modified_gmt":"2020-09-20T18:28:38","slug":"intersection-of-a-ray-and-a-plane","status":"publish","type":"post","link":"http:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/","title":{"rendered":"Intersection of a ray and a plane"},"content":{"rendered":"\n<p>I previously showed the derivation of how to <a href=\"http:\/\/lousodrome.net\/blog\/light\/2017\/01\/03\/intersection-of-a-ray-and-a-cone\/\">determine the intersection of a plane and a cone<\/a>. At the time I had to solve that equation, so after doing so I decided to publish it for anyone to use. Given the positive feedback, it seems this was useful, so I might as well continue with a few more.<\/p>\n\n\n\n<p>Here is probably the most basic intersection: a ray and a plane. Solving it is straightforward, which I hope can be seen below. Like last time, I am using vector notation.<\/p>\n\n\n\n<ol><li>We define a ray with its origin $O$ and its direction as a unit vector $\\hat{D}$.<br>Any point $X$ on the ray at a signed distance $t$ from the origin of the ray verifies: $\\vec{X} = \\vec{O} + t\\vec{D}$.<br>When $t$ is positive $X$ is in the direction of the ray, and when $t$ is negative $X$ is in the opposite direction.<\/li><li>We define a plane with a point $S$ on that plane and the normal unit vector $\\hat{N}$, perpendicular to the plane.<br>The distance between any point $X$ and the plane is $d = \\lvert (\\vec{X} &#8211; \\vec{S}) \\cdot \\vec{N} \\rvert$. If this equality is not obvious for you, you can think of it as the distance between $X$ and $S$ along the $\\vec{N}$ direction. When $d=0$, it means $X$ is on the plane itself. <\/li><li>We define $P$ the intersection or the ray and the plane, and which we are interested in finding.<\/li><\/ol>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter is-resized\"><img decoding=\"async\" loading=\"lazy\" src=\"\/blog\/wp-content\/images\/plane-ray-intersection.png\" alt=\"\" width=\"318\" height=\"240\"\/><\/figure><\/div>\n\n\n\n<p>Since $P$ is both on the ray and on the plane, we can write: $$ \\left\\{ \\begin{array}{l} \\vec{P}=\\vec{O} + t\\vec{D} \\\\ \\lvert (\\vec{P} &#8211; \\vec{S}) \\cdot \\vec{N} \\rvert = 0 \\end{array} \\right. $$ Because the distance $d$ from the plane is $0$, the absolute value is irrelevant here. We can just write: $$ \\left\\{ \\begin{array}{l} \\vec{P}=\\vec{O} + t\\vec{D} \\\\<br>(\\vec{P} &#8211; \\vec{S}) \\cdot \\vec{N} = 0 \\end{array} \\right. $$ All we have to do is replace $P$ with $\\vec{O} + t\\vec{D}$ in the second equation, and  reorder the terms to get $t$ on one side.<br> $$ (\\vec{O} + t\\vec{D} &#8211; \\vec{S}) \\cdot \\vec{N} = 0 $$ $$ \\vec{O} \\cdot \\vec{N}  + t\\vec{D} \\cdot \\vec{N}  &#8211; \\vec{S} \\cdot \\vec{N} = 0 $$ $$ t\\vec{D} \\cdot \\vec{N} = \\vec{S} \\cdot \\vec{N} &#8211; \\vec{O} \\cdot \\vec{N} $$ $$ t = \\frac{(\\vec{S} &#8211; \\vec{O}) \\cdot \\vec{N}}{ \\vec{D} \\cdot \\vec{N} } $$<\/p>\n\n\n\n<p>A question to ask ourselves is: what about the division by $0$? Looking at the diagram, we can see that $\\vec{D} \\cdot \\vec{N} = 0$ means the ray is parallel to the plane, and there is no solution unless $O$ is already on the plane. Otherwise, the ray intersects the plane for the value of $t$ written above.  That&#8217;s it, we&#8217;re done.<\/p>\n\n\n\n<p><strong>Note:<\/strong> There are several, equivalent, ways of representing a plane. If your plane is not defined by a point $S$ and a normal vector $\\hat{N}$, but rather with a distance to the origin $s$ and a normal vector $\\hat{N}$, you can notice that $s = \\vec{S} \\cdot \\vec{N}$ and simplify the result above, which becomes:  $$ t = \\frac{s &#8211; \\vec{O} \\cdot \\vec{N}}{ \\vec{D} \\cdot \\vec{N} } $$ <\/p>\n\n\n\n<hr>\n\n\n\n<h2>Signed distance to a plane<\/h2>\n\n\n\n<p>For the sake of simplicity, in the above we defined the distance to the plane as an absolute value. It is possible however to define it as a signed value:  $d = (\\vec{X} &#8211; \\vec{S}) \\cdot \\vec{N}$. In this case $d&gt;0$ means $X$ is somewhere on the side of the plane pointed by  $\\vec{N}$, while $d&lt;0$ means $X$ is on the  opposite side of the  plane.<br><br>Distances that can be negative are called signed distances, and they are a foundation of Signed Distance Fields (SDF).<br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I previously showed the derivation of how to determine the intersection of a plane and a cone. At the time I had to solve that equation, so after doing so I decided to publish it for anyone to use. Given &hellip; <a href=\"http:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,17],"tags":[890,888,135,371,296,889,126,133],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.13 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Intersection of a ray and a plane &ndash; Light is beautiful<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Intersection of a ray and a plane &ndash; Light is beautiful\" \/>\n<meta property=\"og:description\" content=\"I previously showed the derivation of how to determine the intersection of a plane and a cone. At the time I had to solve that equation, so after doing so I decided to publish it for anyone to use. Given &hellip; Continue reading &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/\" \/>\n<meta property=\"og:site_name\" content=\"Light is beautiful\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-03T02:11:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-09-20T18:28:38+00:00\" \/>\n<meta name=\"author\" content=\"Julien Guertault\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Zavie\" \/>\n<meta name=\"twitter:site\" content=\"@Zavie\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Julien Guertault\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/\"},\"author\":{\"name\":\"Julien Guertault\",\"@id\":\"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/a16a2a69d73eca763ffdf125c49eaa2f\"},\"headline\":\"Intersection of a ray and a plane\",\"datePublished\":\"2020-07-03T02:11:45+00:00\",\"dateModified\":\"2020-09-20T18:28:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/\"},\"wordCount\":651,\"commentCount\":0,\"publisher\":{\"@id\":\"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/a16a2a69d73eca763ffdf125c49eaa2f\"},\"keywords\":[\"analytical solution\",\"equation\",\"linear algebra\",\"math\",\"plane\",\"ray\",\"ray tracing\",\"vector\"],\"articleSection\":[\"Random\",\"Rendering\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/\",\"url\":\"https:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/\",\"name\":\"Intersection of a ray and a plane &ndash; Light is beautiful\",\"isPartOf\":{\"@id\":\"http:\/\/lousodrome.net\/blog\/light\/#website\"},\"datePublished\":\"2020-07-03T02:11:45+00:00\",\"dateModified\":\"2020-09-20T18:28:38+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/lousodrome.net\/blog\/light\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Intersection of a ray and a plane\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/lousodrome.net\/blog\/light\/#website\",\"url\":\"http:\/\/lousodrome.net\/blog\/light\/\",\"name\":\"Light is beautiful\",\"description\":\"Thoughts of a graphics programmer, demoscener and spare time photographer\",\"publisher\":{\"@id\":\"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/a16a2a69d73eca763ffdf125c49eaa2f\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/lousodrome.net\/blog\/light\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/a16a2a69d73eca763ffdf125c49eaa2f\",\"name\":\"Julien Guertault\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/2.gravatar.com\/avatar\/2e5fc7a18e1701e1bb61a5da0ef35cf7?s=96&d=identicon&r=g\",\"contentUrl\":\"http:\/\/2.gravatar.com\/avatar\/2e5fc7a18e1701e1bb61a5da0ef35cf7?s=96&d=identicon&r=g\",\"caption\":\"Julien Guertault\"},\"logo\":{\"@id\":\"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/image\/\"},\"url\":\"http:\/\/lousodrome.net\/blog\/light\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Intersection of a ray and a plane &ndash; Light is beautiful","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/","og_locale":"en_US","og_type":"article","og_title":"Intersection of a ray and a plane &ndash; Light is beautiful","og_description":"I previously showed the derivation of how to determine the intersection of a plane and a cone. At the time I had to solve that equation, so after doing so I decided to publish it for anyone to use. Given &hellip; Continue reading &rarr;","og_url":"https:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/","og_site_name":"Light is beautiful","article_published_time":"2020-07-03T02:11:45+00:00","article_modified_time":"2020-09-20T18:28:38+00:00","author":"Julien Guertault","twitter_card":"summary_large_image","twitter_creator":"@Zavie","twitter_site":"@Zavie","twitter_misc":{"Written by":"Julien Guertault","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/#article","isPartOf":{"@id":"https:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/"},"author":{"name":"Julien Guertault","@id":"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/a16a2a69d73eca763ffdf125c49eaa2f"},"headline":"Intersection of a ray and a plane","datePublished":"2020-07-03T02:11:45+00:00","dateModified":"2020-09-20T18:28:38+00:00","mainEntityOfPage":{"@id":"https:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/"},"wordCount":651,"commentCount":0,"publisher":{"@id":"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/a16a2a69d73eca763ffdf125c49eaa2f"},"keywords":["analytical solution","equation","linear algebra","math","plane","ray","ray tracing","vector"],"articleSection":["Random","Rendering"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/","url":"https:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/","name":"Intersection of a ray and a plane &ndash; Light is beautiful","isPartOf":{"@id":"http:\/\/lousodrome.net\/blog\/light\/#website"},"datePublished":"2020-07-03T02:11:45+00:00","dateModified":"2020-09-20T18:28:38+00:00","breadcrumb":{"@id":"https:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/lousodrome.net\/blog\/light\/2020\/07\/03\/intersection-of-a-ray-and-a-plane\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/lousodrome.net\/blog\/light\/"},{"@type":"ListItem","position":2,"name":"Intersection of a ray and a plane"}]},{"@type":"WebSite","@id":"http:\/\/lousodrome.net\/blog\/light\/#website","url":"http:\/\/lousodrome.net\/blog\/light\/","name":"Light is beautiful","description":"Thoughts of a graphics programmer, demoscener and spare time photographer","publisher":{"@id":"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/a16a2a69d73eca763ffdf125c49eaa2f"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/lousodrome.net\/blog\/light\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/a16a2a69d73eca763ffdf125c49eaa2f","name":"Julien Guertault","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/image\/","url":"http:\/\/2.gravatar.com\/avatar\/2e5fc7a18e1701e1bb61a5da0ef35cf7?s=96&d=identicon&r=g","contentUrl":"http:\/\/2.gravatar.com\/avatar\/2e5fc7a18e1701e1bb61a5da0ef35cf7?s=96&d=identicon&r=g","caption":"Julien Guertault"},"logo":{"@id":"http:\/\/lousodrome.net\/blog\/light\/#\/schema\/person\/image\/"},"url":"http:\/\/lousodrome.net\/blog\/light\/author\/admin\/"}]}},"_links":{"self":[{"href":"http:\/\/lousodrome.net\/blog\/light\/wp-json\/wp\/v2\/posts\/1516"}],"collection":[{"href":"http:\/\/lousodrome.net\/blog\/light\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/lousodrome.net\/blog\/light\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/lousodrome.net\/blog\/light\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/lousodrome.net\/blog\/light\/wp-json\/wp\/v2\/comments?post=1516"}],"version-history":[{"count":65,"href":"http:\/\/lousodrome.net\/blog\/light\/wp-json\/wp\/v2\/posts\/1516\/revisions"}],"predecessor-version":[{"id":1677,"href":"http:\/\/lousodrome.net\/blog\/light\/wp-json\/wp\/v2\/posts\/1516\/revisions\/1677"}],"wp:attachment":[{"href":"http:\/\/lousodrome.net\/blog\/light\/wp-json\/wp\/v2\/media?parent=1516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/lousodrome.net\/blog\/light\/wp-json\/wp\/v2\/categories?post=1516"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/lousodrome.net\/blog\/light\/wp-json\/wp\/v2\/tags?post=1516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}