Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6098995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:13:20+00:00 2026-05-23T13:13:20+00:00

I am tracking objects for which I need to test if they are located

  • 0

I am tracking objects for which I need to test if they are located inside or outside a cube / bounding box. If they are outside, I do a ray-plane intersection to calculate a point on one of the planes of the cube. The ray starts at the center of the box, and points towards the object. The plane is one of the 6 which make up the cube.

What I would like to avoid is that I am testing the ray-plane intersection on every one of the 6 planes all the time. So I thought I’d be clever and calculate first the dot product between each of the plane normals and the ray. Then select the one which has the smallest angle (closest to 1).

This works only halfway. There are locations when the object is aligned with one of the planes, where my function selects the wrong plane. Most of the time it works though, and I wonder why that is. I figure there must be something fundamentally wrong with my approach.

Here are my defined planes, which each have a label. The 0,0,0 of the coordinate system is one corner of the cube.

planes = {
    xnear = { normal = {1, 0, 0}, d = 0 },
    xfar = { normal = {-1, 0, 0}, d = cubeSize.x },
    ynear = { normal = {0, 1, 0}, d = 0 },
    yfar = { normal = {0, -1, 0}, d = cubeSize.y },
    znear = { normal = {0, 0, 1}, d = 0 },
    zfar = { normal = {0, 0, -1}, d = cubeSize.z }, 
}

Then I use the following function:

-- Determine what plane to use for collision testing. The angle is calculated
-- between the plane normal and the direction of the ray
function whatPlane(pos)
local direction = vec3.sub(cubeCenter, pos)
local result
local max = -1
for label, plane in pairs(planes) do
    local dotproduct = vec3.dot(plane.normal, direction)
    if dotproduct > max then
        max = dotproduct
        result = label
    end
end
return result
end

What I’m I missing here?

I guess I could just do the collision test on every plane and then choose the point which is closest to the center of the cube, but that seems like a waste.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T13:13:20+00:00Added an answer on May 23, 2026 at 1:13 pm

    Your argument would be fine if the cube was indeed a cube, i.e. all dimensions are the same (and only for the case of being in the center of a regular polyhedron). But as it looks like you have different dimension for each of the axes.

    If one length is rather small (think of a very thin box) no matter what direction you look in almost any case you’ll hit those big planes and almost never the thin sides.

    You can compensate this if you scale your direction by the exact lengths of the box. I.e. instead of direction you use direction/(cubeSize.x,cubeSize.y,cubeSize.z) where the divison is done by coordinate.

    Another remark: note that the comparison works fine, also with unnormalized direction but you may run into problems in other if you keep your dot-product unnormalized.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to implement a large collection of Widget objects, each of which contain
I am building a table for tracking the history of particular objects in my
i want to add tracking to my website. I saw google analytics which seems
I need to create HarrCascade XML file to use it with OpenCV for tracking
I need to track which instance created another instance. It's an instancing hierarchy not
I have a graph object, that I need to serialize. Nomatter which members i
I want to create an integration test which grabs an EF entity from the
I have a table which includes 230 columns and 12 million rows. I need
I have a WCF client which passes Self-Tracking Entities to a WPF application built
For one of my projects I have a tree of QObject derived objects, which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.