1

I am doing a raytracing and it is going pretty well, I introduced 4 differents shapes (square, triangle, plane, sphere). Now I need to introduce a cylinder but I am facing a problem on it. All the documentations I find are starting with the assumption

it is aligned with the Z axis

Which is not my case here ! My cylinder is defined by a point, a width, a height and a rotation. I started researching but all the solutions imply that the cylinder is aligned with an axis and I can not find how to use it.

Vertexwahn
  • 7,709
  • 6
  • 64
  • 90
ORoberts
  • 67
  • 8
  • 1
    You have a line (the ray) ยท`L` in a coordinate frame F_1. The cylinder `C` in that coordinate frame is not aligned with the `z` axis. Rotate the coordinate frame so that `C` becomes aligned with the `z` axis. Call the result `F_2`. Apply the reverse transformation to `L`. Now both `L` and and `C` are expressed relative to `F_2`, and you can use the algorithms that you have found. Once you find the intersection, transform that back to the original coordinate frame. โ€“ Ash Dec 20 '19 at 10:57
  • instead of rotations define your cylinder by its 3 basis vectors (2 on base and one for its axis) and radius and height (they can be encoded as size of the basis vectors) from there its easy to convert to axis aligned cylinder just compute the `dot(vector,basis_vector)` that will give you coordinate in axis aligned cylinder ...so do this for all the basis vectors and that is it ... see [Generating 3D Cylinder with Rotationmatrix](https://stackoverflow.com/a/41813188/2521214) โ€“ Spektre Dec 21 '19 at 10:29
  • http://www.pbr-book.org/3ed-2018/Shapes/Cylinders.html โ€“ Vertexwahn Dec 21 '19 at 13:04

0 Answers0