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

  • SEARCH
  • Home
  • 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 959211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:59:18+00:00 2026-05-16T00:59:18+00:00

Looking for code to detect an intersection between a 3D segment (not a line/ray)

  • 0

Looking for code to detect an intersection between a 3D segment (not a line/ray) and a 3D box (not necessarily a cube, but always axis-aligned). The boxes are voxels so they have regular spacing.

Already have the code to find a segment/plane intersection. Ideally, I’d like to find an efficient solution to adapt this for a rectangle, repeat for each face of the 3d box, and then iterate for tens of thousands of segments and boxes.

seg_start = array([x1,y1,z1])
seg_end = array([x2,y2,z2])
plane_point = array([x3,y3,z3])
plane_normal = array([x4,y4,z4])
u = seg_end - seg_start
w = seg_start - plane_point
D = dot(plane_normal,u)
N = -dot(plane_normal,w)
sI = N / D
if sI >= 0 and sI <= 1:
    return 1
  • 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-16T00:59:19+00:00Added an answer on May 16, 2026 at 12:59 am

    First off, you probably meant and rather than or in your if-condition, otherwise it’ll just always return true. Second, if you’re just testing whether there is an intersection or not, you can do it faster (without the float-division):

    • You can determine which “side” of each plane any given point is on using vector math:
      side = dot(my_point - plane_point, plane_normal)
      Now if side is positive, my_point is “in front of” the plane (i.e. it’s on the side the normal is pointing towards); if negative, it’s “behind” the plane. If side is zero, your point lies on the plane.
    • You can check whether your segment intersects an (infinite) plane by just testing to see if the start point and end point are on different sides:

      start_side = dot(seg_start - plane_point, plane_normal)
      end_side = dot(seg_end - plane_point, plane_normal)
      return start_side * end_side
      #if < 0, both points lie on different sides, hence intersection
      #if = 0, at least one point lies on the plane
      #if > 0, both points lie on the same side, i.e. no intersection
      
    • You can use the “side” check to do the axis-aligned-cuboid intersection too (actually, this will work for any parallelpiped):

      • Treat your box as a set of six planes
      • Make sure the plane normals are all pointing either “outwards” or “inwards” from the box. I’ll assume you’re using “outwards”
      • For any point to lie inside your box, it has to be “behind” all six planes. If it isn’t, it lies outside the box.
      • For any segment to intersect the box, one point has to lie outside it and one inside.
      • That’s all!

    edit: The last point is actually incorrect; as you say, voxels can be intersected even if both endpoints lie outside. So it’s not the whole solution – actually, you can’t really do this without calculating the intersection point. You can, however, still use the “side test” as an early-reject mechanism, so as to cut down on the number of full calculations you need to do: if both points are on the same side of any one of the six planes, there can be no intersection.

    As far as your specific case goes, it seems like you’re trying to find all intersecting voxels for some given line segment? In that case, you’d probably be better served using something like Bresenham’s to explicitly calculate the path, instead of testing for intersections against all of the voxels…

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

Sidebar

Ask A Question

Stats

  • Questions 530k
  • Answers 530k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There are several problems with your benchmarks. First, your benchmark… May 16, 2026 at 11:27 pm
  • Editorial Team
    Editorial Team added an answer @activity.clienships.delete_if{|o| o.client_id == 24} May 16, 2026 at 11:27 pm
  • Editorial Team
    Editorial Team added an answer Ok, I figured this it out. The problem was that… May 16, 2026 at 11:27 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have been searching everywhere but I could not find an answer. I need
I am looking for some code that will return me values if the user
I'm looking for a way to detect the # of running processes that has
I currently have the following code: events.detect do |event| #detect does the block until
I'm looking for a concise way to compare two arrays for any match. I
I want to be able to detect whenever new files are created or existing
I'm working on an app that needs to detect a rotation gesture from the
What is the best practice (interface and implementation) for a command line tool that
Is there any tool that enables you to hot swap JavaScript contents while executing
In our application, we receive text files ( .txt , .csv , etc.) from

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.