How to develop a function that creates a finite vector space?

2 views (last 30 days)
I'm looking to create a function that which passes in three dimensions to create a room (a cube) such that it has defined boundaries. When a vector inside the cube intersects with one of these boundaries I want the vector to end and its point of intersection returned.
  1 Comment
John D'Errico
John D'Errico on 22 May 2019
Edited: John D'Errico on 22 May 2019
What do you mean to create a vector space? Passing in dimensions? You seem to be mis-using mathematical jargon in ways that make no sense.
You apparently want to find the intersection of a ray with the boundary of a cube. Nothing special, and no need to create anything fancy. No need for vector spaces, and certainly not finite ones. A vector space is a mathematical concept. Computers do not create mathematical concepts. You do, in your mind.
A ray is defined by a start point, and a vector that defines the direction the ray points in. It extends to infinity. You can define that ray using two vectors, and a parameter that I'll call t. So if the base of the ray is the point P0, and the direction vector P, then we have:
P(t)= P0 + t*P
Here P0 and P are indeed vectors in MATLAB, but that just means they are composed of three numbers. Numbers mean whatever you want them to mean.
Don't make things complicated when there is no need to do so.
How do you find the intersection of a ray with a box (a cube)?
  1. Verify that the base of the ray is inside the box. If it is not, then there may be 0, 1, or 2 intersections with the box, but I think you are not interested in those cases.
  2. Write a code that finds the intersection of the ray with a plane. That takes not much more than a dot product, since the normal to the plane is known and easy to write for such a box. Remember that a plane is defined by a point in the plane, and the normal vector to the plane.
  3. If the intersection occurs for positive t, AND it crosses the plane inside the boundaries of the face of the cube, then it intersects that face of the cube.
  4. Now just test all 6 faces of the cube for an intersection. You can stop as soon as you find an intersection, as long as the base of the ray was inside the box itself.
Too often I see people make things seem overly complex when there is no need for mathematical sophistication.

Sign in to comment.

Answers (1)

Matt J
Matt J on 22 May 2019
You can use intersectionHull in this FEX package
Example 2 in the help documentation is very similar to what you describe.

Categories

Find more on Operators and Elementary Operations in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!