{"id":552,"date":"2024-09-08T20:59:57","date_gmt":"2024-09-08T18:59:57","guid":{"rendered":"https:\/\/heikkili.kapsi.fi\/blog\/?p=552"},"modified":"2024-09-08T20:59:58","modified_gmt":"2024-09-08T18:59:58","slug":"cse168-notes-2-intersections","status":"publish","type":"post","link":"http:\/\/heikkili.kapsi.fi\/blog\/?p=552","title":{"rendered":"CSE168 Notes 2, intersections"},"content":{"rendered":"\n<p>&nbsp;Raytracing 1: Intersections<\/p>\n\n\n\n<p>different type of rays need different information,<strong> shadow rays<\/strong> intersection \/ no intersection. <strong>primary rays<\/strong>: point of intersection materials, normal, text coord .. etc<\/p>\n\n\n\n<p><strong>Ray-Sphere Intersection<\/strong><\/p>\n\n\n<p><img decoding=\"async\" src=\"http:\/\/s0.wp.com\/latex.php?latex=+Ray+%3D+%5Cvec%7BP%7D+%3D+%5Cvec%7BP%7D_0+%2B+%5Cvec%7BP%7D_1+t+&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\" Ray = &#92;vec{P} = &#92;vec{P}_0 + &#92;vec{P}_1 t \" class=\"latex\" \/><br \/>\n<img decoding=\"async\" src=\"http:\/\/s0.wp.com\/latex.php?latex=+Sphere+%3D+%28%5Cvec%7BP%7D+-+%5Cvec%7BC%7D%29+%5Ccdot+%28%5Cvec%7BP%7D+-+%5Cvec%7BC%7D%29+-+r%5E2+%3D+0+&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\" Sphere = (&#92;vec{P} - &#92;vec{C}) &#92;cdot (&#92;vec{P} - &#92;vec{C}) - r^2 = 0 \" class=\"latex\" \/><\/p>\n\n\n\n<p>Substitute:<\/p>\n\n\n<img decoding=\"async\" src=\"http:\/\/s0.wp.com\/latex.php?latex=+Sphere+%3D+%28%5Cvec%7BP%7D_0+%2B+%5Cvec%7BP%7D_1+t+-+%5Cvec%7BC%7D%29+%5Ccdot+%28%5Cvec%7BP%7D_0+%2B+%5Cvec%7BP%7D_1+t+-+%5Cvec%7BC%7D%29+-+r%5E2+%3D+0++&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\" Sphere = (&#92;vec{P}_0 + &#92;vec{P}_1 t - &#92;vec{C}) &#92;cdot (&#92;vec{P}_0 + &#92;vec{P}_1 t - &#92;vec{C}) - r^2 = 0  \" class=\"latex\" \/>\n\n\n\n<p>Simplify<\/p>\n\n\n\n<p>Substitute:<\/p>\n\n\n<img decoding=\"async\" src=\"http:\/\/s0.wp.com\/latex.php?latex=+Sphere+%3D+t%5E2+%28+%5Cvec%7BP%7D_1+%5Ccdot+%5Cvec%7BP%7D_1%29+%2B+2+t+%5Cvec%7BP%7D_1+%5Ccdot++%28%5Cvec%7BP%7D_0+-+%5Cvec%7BC%7D%29+%2B+%28%5Cvec%7BP%7D_0+-+%5Cvec%7BC%7D%29+%5Ccdot++%28%5Cvec%7BP%7D_0+-+%5Cvec%7BC%7D%29+-+r%5E2+%3D+0+&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\" Sphere = t^2 ( &#92;vec{P}_1 &#92;cdot &#92;vec{P}_1) + 2 t &#92;vec{P}_1 &#92;cdot  (&#92;vec{P}_0 - &#92;vec{C}) + (&#92;vec{P}_0 - &#92;vec{C}) &#92;cdot  (&#92;vec{P}_0 - &#92;vec{C}) - r^2 = 0 \" class=\"latex\" \/>\n\n\n\n<p>quadratic equation for t<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>2 real positive roots: pick smaller root<\/li>\n\n\n\n<li>both  roots same: tangent to sphere<\/li>\n\n\n\n<li>one positive, one negative root:  ray origin inside sphere (  pic + root)<\/li>\n\n\n\n<li>complex roots: not intersection (check discriminant of equation first)<\/li>\n<\/ul>\n\n\n\n<p>Intersection point <\/p>\n\n\n\n<p>substitute t back to the ray equation. surface normal at point of intersection:<\/p>\n\n\n<img decoding=\"async\" src=\"http:\/\/s0.wp.com\/latex.php?latex=+%5Cvec%7BN%7D+%3D+%5Cfrac%7B%5Cvec%7BP%7D+-+%5Cvec%7BC%7D%7D%7B%7C%5Cvec%7BP%7D+-+%5Cvec%7BC%7D%7C%7D+&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\" &#92;vec{N} = &#92;frac{&#92;vec{P} - &#92;vec{C}}{|&#92;vec{P} - &#92;vec{C}|} \" class=\"latex\" \/>\n\n\n\n<p><strong>Ray-Triangle Intersection<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>one approach: Ray-Plane intersection, then check if inside triangle<\/li>\n<\/ul>\n\n\n<img decoding=\"async\" src=\"http:\/\/s0.wp.com\/latex.php?latex=+plane+%3D+%5Cvec%7BP%7D+%5Ccdot+%5Cvec%7Bn%7D+-+%5Cvec%7BA%7D+%5Ccdot+%5Cvec%7Bn%7D+%3D+0+&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\" plane = &#92;vec{P} &#92;cdot &#92;vec{n} - &#92;vec{A} &#92;cdot &#92;vec{n} = 0 \" class=\"latex\" \/>\n\n\n\n<p>Combine with ray equation<\/p>\n\n\n<img decoding=\"async\" src=\"http:\/\/s0.wp.com\/latex.php?latex=+t+%3D++%5Cfrac+%7B+%5Cvec%7BA%7D+%5Ccdot+%5Cvec%7Bn%7D+-+%5Cvec%7BP%7D_0+%5Ccdot+%5Cvec%7Bn%7D+%7D%7B+%5Cvec%7BP%7D_1+%5Ccdot+%5Cvec%7Bn%7D%7D+&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002\" alt=\" t =  &#92;frac { &#92;vec{A} &#92;cdot &#92;vec{n} - &#92;vec{P}_0 &#92;cdot &#92;vec{n} }{ &#92;vec{P}_1 &#92;cdot &#92;vec{n}} \" class=\"latex\" \/>\n\n\n\n<ul class=\"wp-block-list\">\n<li>still need to find intersection point inside the polygon<\/li>\n\n\n\n<li>Ray intersection inside triangle odd amount in, even out<\/li>\n\n\n\n<li>we find parametrically [barycentric coordinates] <\/li>\n<\/ul>\n\n\n\n<p><strong>Other primitives<\/strong>: cones, cylinders, ellipsoids<\/p>\n\n\n\n<p>Boxes (useful for bounding boxes)<\/p>\n\n\n\n<p>Many more primitives<\/p>\n\n\n\n<p><strong>Ray-Tracing Transformed objects<\/strong><\/p>\n\n\n\n<p>We have ray-sphere test but want to test ellipsoid<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>apply inverse transform to ray, use ray-sphere<\/li>\n\n\n\n<li>allows instancing<\/li>\n\n\n\n<li>general 4&#215;4 transform M (matrix stacks)<\/li>\n\n\n\n<li>apply inverse transform of M to ray<\/li>\n\n\n\n<li>do standard ray-surface intersection as modified<\/li>\n\n\n\n<li>transform intersection back to actual coordinates<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;Raytracing 1: Intersections different type of rays need different information, shadow rays intersection \/ no intersection. primary rays: point of intersection materials, normal, text coord .. etc Ray-Sphere Intersection Substitute: Simplify Substitute: quadratic equation for t Intersection point substitute t back to the ray equation. surface normal at point of intersection: Ray-Triangle Intersection Combine with&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6,43,7,1],"tags":[10,42,12,11,9],"class_list":["post-552","post","type-post","status-publish","format-standard","hentry","category-computer-graphics","category-cse168","category-raytracing","category-uncategorized","tag-computer-graphics","tag-cse168","tag-edx","tag-ray-tracing","tag-raytracing"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p7k3DT-8U","_links":{"self":[{"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=\/wp\/v2\/posts\/552"}],"collection":[{"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=552"}],"version-history":[{"count":20,"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=\/wp\/v2\/posts\/552\/revisions"}],"predecessor-version":[{"id":572,"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=\/wp\/v2\/posts\/552\/revisions\/572"}],"wp:attachment":[{"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=552"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=552"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/heikkili.kapsi.fi\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}