doja
The Ray Tracer Challenge: Cylinder test #7 (p185) - failed corner cases
Hi,
I’m stuck on the test for #7 “Intersecting the caps of a closed cylinder”.
Tests 3 & 5 are failing as the intersections count is equal to one (one the cap intersection is detected).
After staring at the code for some time, any help is appreciated!
override internal func shapeSpecificIntersection(transformedRay:Ray<T>) -> Array<Intersection<T>> {
var result = Array<Intersection<T>>()
let a = transformedRay.direction.x * transformedRay.direction.x + transformedRay.direction.z * transformedRay.direction.z
let b = 2 * transformedRay.origin.x * transformedRay.direction.x +
2 * transformedRay.origin.z * transformedRay.direction.z
if (a.magnitude < Self.defaultEpsilon || b.magnitude < Self.defaultEpsilon) {
return intersectCaps(ray: transformedRay)
}
let c = transformedRay.origin.x * transformedRay.origin.x + transformedRay.origin.z * transformedRay.origin.z - 1
let disc = b * b - 4 * a * c
if (disc < 0) {
return intersectCaps(ray: transformedRay)
}
var t0 = (-b - sqrt(disc)) / (2 * a)
var t1 = (-b + sqrt(disc)) / (2 * a)
if t0 > t1 {
let tmp = t1
t1 = t0
t0 = tmp
}
let y0 = transformedRay.origin.y + t0 * transformedRay.direction.y
if minimum < y0 && y0 < maximum {
result.append(Intersection<T>(shape: self, t: t0))
}
let y1 = transformedRay.origin.y + t1 * transformedRay.direction.y
if minimum < y1 && y1 < maximum {
result.append(Intersection<T>(shape: self, t: t1))
}
result.append(contentsOf: intersectCaps(ray: transformedRay))
return result
}
func checkCap(ray: Ray<T>, t: T) -> Bool {
let x = ray.origin.x + t * ray.direction.x
let z = ray.origin.z + t * ray.direction.z
return (x * x) + (z * z) <= 1
}
func intersectCaps(ray: Ray<T>) -> Array<Intersection<T>> {
var result = Array<Intersection<T>>()
if !closed {
return result
}
var t = (minimum - ray.origin.y) / ray.direction.y
if (checkCap(ray: ray, t: t)) {
result.append(Intersection<T>(shape: self, t: t))
}
t = (maximum - ray.origin.y) / ray.direction.y
if (checkCap(ray:ray, t: t)) {
result.append(Intersection<T>(shape: self, t: t))
}
return result
}
Best regards & happy coding! doja
Popular Pragmatic Bookshelf topics
As per the title, thanks.
New
Some minor things in the paper edition that says “3 2020” on the title page verso, not mentioned in the book’s errata online:
p. 186 But...
New
Hi Travis! Thank you for the cool book! :slight_smile:
I made a list of issues and thought I could post them chapter by chapter. I’m rev...
New
#book-python-testing-with-pytest-second-edition
Hi. Thanks for writing the book. I am just learning so this might just of been an issue ...
New
I ran this command after installing the sample application:
$ cards add do something --owner Brian
And got a file not found error:
Fil...
New
When running tox for the first time, I got the following error:
ERROR: InterpreterNotFound: python3.10
I realised that I was running ...
New
I’m a newbie to Rails 7 and have hit an issue with the bin/Dev script mentioned on pages 112-113.
Iteration A1 - Seeing the list of prod...
New
It seems the second code snippet is missing the code to set the current_user:
current_user: Accounts.get_user_by_session_token(session["...
New
@parrt
In the context of Chapter 4.3, the grammar Java.g4, meant to parse Java 6 compilation units, no longer passes ANTLR (currently 4....
New
root_layout: {PentoWeb.LayoutView, :root},
This results in the following following error:
no “root” html template defined for PentoWeb...
New
Other popular topics
Hello Devtalk World!
Please let us know a little about who you are and where you’re from :nerd_face:
New
Design and develop sophisticated 2D games that are as much fun to make as they are to play. From particle effects and pathfinding to soci...
New
Just done a fresh install of macOS Big Sur and on installing Erlang I am getting:
asdf install erlang 23.1.2
Configure failed.
checking ...
New
I have seen the keycaps I want - they are due for a group-buy this week but won’t be delivered until October next year!!! :rofl:
The Ser...
New
Tailwind CSS is an exciting new CSS framework that allows you to design your site by composing simple utility classes to create complex e...
New
Oh just spent so much time on this to discover now that RancherOS is in end of life but Rancher is refusing to mark the Github repo as su...
New
Intensively researching Erlang books and additional resources on it, I have found that the topic of using Regular Expressions is either c...
New
Saw this on TikTok of all places! :lol:
Anyone heard of them before?
Lite:
New
Curious what kind of results others are getting, I think actually prefer the 7B model to the 32B model, not only is it faster but the qua...
New
Background
Lately I am in a quest to find a good quality TTS ai generation tool to run locally in order to create audio for some videos I...
New
Categories:
Sub Categories:
Popular Portals
- /elixir
- /rust
- /ruby
- /wasm
- /erlang
- /phoenix
- /keyboards
- /python
- /js
- /rails
- /security
- /go
- /swift
- /vim
- /clojure
- /emacs
- /haskell
- /java
- /svelte
- /onivim
- /typescript
- /kotlin
- /c-plus-plus
- /crystal
- /tailwind
- /react
- /gleam
- /ocaml
- /flutter
- /elm
- /vscode
- /ash
- /opensuse
- /html
- /centos
- /deepseek
- /zig
- /php
- /scala
- /sublime-text
- /textmate
- /lisp
- /react-native
- /debian
- /nixos
- /agda
- /kubuntu
- /django
- /arch-linux
- /deno
- /nodejs
- /revery
- /ubuntu
- /manjaro
- /spring
- /diversity
- /lua
- /julia
- /markdown
- /c








