Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Because your ray starts at the centre of the cube, you can easily tell which face of the cube it hits. Simply find the component of u that has the largest magnitude - it's one of the faces with normals pointing along that axis. The sign of that component will tell you which of those two faces it intersects.

For example, if u is (3, -5, 4) then it hits the face of the cube with its normal pointing in the (0, -1, 0) direction (probably the bottom one, but it depends on your coordinate system).

From there you can do a ray vs plane intersectionray vs plane intersection against that cube face.

However, you can simplify that process. In our example, we know that the point of intersection on the y axis is -d/2. So you can just scale u by d/(2*5) to make the y component end up where we want it. That gives us (3d/10, -d/2, 4d/10). If I haven't made any silly mistakes that will be your intersection point on the cube.

Because your ray starts at the centre of the cube, you can easily tell which face of the cube it hits. Simply find the component of u that has the largest magnitude - it's one of the faces with normals pointing along that axis. The sign of that component will tell you which of those two faces it intersects.

For example, if u is (3, -5, 4) then it hits the face of the cube with its normal pointing in the (0, -1, 0) direction (probably the bottom one, but it depends on your coordinate system).

From there you can do a ray vs plane intersection against that cube face.

However, you can simplify that process. In our example, we know that the point of intersection on the y axis is -d/2. So you can just scale u by d/(2*5) to make the y component end up where we want it. That gives us (3d/10, -d/2, 4d/10). If I haven't made any silly mistakes that will be your intersection point on the cube.

Because your ray starts at the centre of the cube, you can easily tell which face of the cube it hits. Simply find the component of u that has the largest magnitude - it's one of the faces with normals pointing along that axis. The sign of that component will tell you which of those two faces it intersects.

For example, if u is (3, -5, 4) then it hits the face of the cube with its normal pointing in the (0, -1, 0) direction (probably the bottom one, but it depends on your coordinate system).

From there you can do a ray vs plane intersection against that cube face.

However, you can simplify that process. In our example, we know that the point of intersection on the y axis is -d/2. So you can just scale u by d/(2*5) to make the y component end up where we want it. That gives us (3d/10, -d/2, 4d/10). If I haven't made any silly mistakes that will be your intersection point on the cube.

Source Link
Adam
  • 7.7k
  • 21
  • 26

Because your ray starts at the centre of the cube, you can easily tell which face of the cube it hits. Simply find the component of u that has the largest magnitude - it's one of the faces with normals pointing along that axis. The sign of that component will tell you which of those two faces it intersects.

For example, if u is (3, -5, 4) then it hits the face of the cube with its normal pointing in the (0, -1, 0) direction (probably the bottom one, but it depends on your coordinate system).

From there you can do a ray vs plane intersection against that cube face.

However, you can simplify that process. In our example, we know that the point of intersection on the y axis is -d/2. So you can just scale u by d/(2*5) to make the y component end up where we want it. That gives us (3d/10, -d/2, 4d/10). If I haven't made any silly mistakes that will be your intersection point on the cube.