## raycasting – How to find if a Ray intersects a Triangle Clockwise or Counter Clockwise

Assume the triangle’s vertices are wound in the order A, B, C

Form a normal to the triangle N = (B – A) x (C – A)

Now you can detect whether your triangle is clockwise or counter-clockwise by the sign of the dot product between this normal and the ray direction

In a left-handed coordinate system:

• Negative = Clockwise from ray’s point of view
• Positive = Counter-clockwise from ray’s point of view

In a right-handed coordinate system, it’s the opposite:

• Negative = Counter-clockwise from ray’s point of view
• Positive = Clockwise from ray’s point of view

## In Quadrilateral ABCD, AD // BC. The bisector of ∠DAB intersects CD at E. BE bisects ∠ABC. Prove that, AB = AD + BC

Geometry , Applications of midpoint theorems

## c++ – How do I determine that the edge of the camera intersects the edge of the background sprite?

I’m trying to make sure that when the camera reaches the border (left or right) of the sprite’s background, a copy of it is spawned from the corresponding side. But I seem to be missing something in the Unreal Engine.

Now I define the intersection of the camera and the sprite boundary as follows:

1. I take the X coordinate of the sprite and subtract half of its size. (Get it’s left border)
2. I also take the camera coordinate and subtract half of the orthographic length (Left border of a screen?)
    ParallaxItems(Index)->GetActorBounds(false, ActorOrigin, BoxExtent, false);

FVector ActorOrigin, BoxExtent;
if ((NewBackgroundPos - BoxExtent.X) >
CamManager->GetCameraLocation().X - (CamManager->GetOrthoWidth() / 2)) {

UE_LOG(LogParallax, Warning, TEXT("Background %d LeftBorder! need spawning"), Index);
}


This seems to be true, but I’m missing something else, perhaps a scale. (But box extent changes correctly) For some reason, the condition is triggered already on the blue line. And this is true for all backgrounds. Somewhere earlier, somewhere later, but player can always see that the background is over. Maybe it’s the orthographic width of the camera? Now it’s 2048.

If I am wrong, please tell me how to do it correctly? Thank you.

## collision detection – Determining first voxel ray intersects

I’m trying to implement the Fast Voxel Traversal Algorithm on a uniform grid of axis-aligned rectangles. Having read the paper, I understand how the traversing works, but not the initialization. I’ve looked around and I did find a readme that overviews the algorithm, but I fail to see how the derive how to determine the index in a data structure (such as an array) that corresponds to the first voxel the ray intersects.

Using the construct presented in the readme, assuming the grid is 2×2 and stored in (going to use Python) an list like so:

+--------+--------+
|        |        |
|        |        |
|  0, 1  |  1, 1  |
|        |        |
|        |        |
+--------+--------+
|        |        |
|        |        |
|  0, 0  |  1, 0  |
|        |        |
|        |        |
+--------+--------+

grid = (((0, 0), (1, 0)),
((0, 1), (1, 1)))


In the overview, the compute r2 = r and resolve t = 27/32, but I fail to see how they translate that to the index grid(0).

Some other resources I’ve used to try and understand:

## java – Determining IF & WHERE a line intersects with a 2D plane (in 3D space)

The following problem im working on is for one of my favorite past-times: game development.

Problem: We’re in 3D space. I’m trying to determine if a line between two vectors in said space is passing through a circle; the latter of which consists of: center vector, radius, yaw & pitch.

In order to determine that, my aim is to convert the circle to a plane which can either be infinite or just have the diameter of the circle for all it’s sides.

Should the line between the two vectors in fact pass through that plane, i am left with the simple task of determining wether that intersection point is within the radius of the circle, in which case i can return either true or false.

What’s already working: I have my circles set up and the general framework is there. The circles are appearing/rendered in the 3D space exactly as specified, great!

What was already tried: Copied some github gist codes and tried to make them work for my purposes. I kinda worked, sometimes at least. Unfortunately due to the nature of how the code was written, i had no idea what it was doing and just scrapped all of that. Researched the topic a lot, too. But due to me not really understanding the language people speak when talking about line/plane intersections, i could have read the answer without recognizing it as such.

Question: I’m stuck at line intersections. No idea where to go and how it works logically! So, where do i go from here and how can one comprehend all of this?

Note: I did tag this issue as “java”, but i’m not looking for spoon-fed code. It’s a logical issue i’m trying to get past. If explained well enough, i will make the code work with trial and error!

## functions – When $f(x)=ax+b$ intersects with $h(x)=cx+d$

I got two functions that draw dots in one dimension, the first one starts with $$b$$, and then draws a dot every $$a$$. And the second one starts with $$d$$ and then draws a dot every $$c$$.

I figure that I have two functions $$f(x)=ax+b$$ and $$h(x)=cx+d$$, and what I need to do is just to compare them, so I am getting $$cx+d=ax+b$$. However, that gives me just one solution while in practice they will intersect at list once every $$ac$$ cycle. How can I find all their intersection points?

## geometry – Line $K$ is parallel to line $U$, and line $L$ intersects line $K$ at point $P$. Show $L nparallel U$.

Working on the book: Lang, Serge & Murrow, Gene. “Geometry – Second Edition” (p. 18)

1. In Figure 1.11, line $$K$$ is parallel to line $$U$$, and line $$L$$ intersects line $$K$$ at point $$P$$. What can you conclude about lines $$L$$ and $$U$$? Why?

PAR 2. Given a line $$L$$ and a point $$P$$, there is one and only one line
passing through $$P$$, parallel to $$L$$.

Conclusion: $$L nparallel U$$

Proof (using Fitch-style natural deduction):

I will assume $$L mathbb{parallel} U$$ and reach a contradiction.

$$deffitch#1#2{quadbegin{array}{|l}#1\hline#2end{array}} defAe#1{qquadmathbf{forall E} : #1 \} defAi#1{qquadmathbf{forall I} : #1 \} defEe#1{qquadmathbf{exists E} : #1 \} defEi#1{qquadmathbf{exists I} : #1 \} defR#1{qquadmathbf{R} : #1 \} defci#1{qquadmathbf{land I} : #1 \} defce#1{qquadmathbf{land E} : #1 \} defoi#1{qquadmathbf{lor I} : #1 \} defoe#1{qquadmathbf{lor E} : #1 \} defii#1{qquadmathbf{to I} : #1 \} defie#1{qquadmathbf{to E} : #1 \} defbe#1{qquadmathbf{leftrightarrow E} : #1 \} defbi#1{qquadmathbf{leftrightarrow I} : #1 \} defqi#1{qquadmathbf{=I}\} defqe#1{qquadmathbf{=E} : #1 \} defne#1{qquadmathbf{neg E} : #1 \} defni#1{qquadmathbf{neg I} : #1 \} defIP#1{qquadmathbf{IP} : #1 \} defx#1{qquadmathbf{X} : #1 \} defDNE#1{qquadmathbf{DNE} : #1 \}$$

$$fitch{1.,K parallel U\ 2.,K neq L\ 3.,P in L land P in K\ 4.,exists!l(Pin l land l parallel U) qquad text{(PAR 2)} }{ fitch{5.,L parallel U}{ fitch{6.,P in l_0 land l parallel U}{ vdots\ }\ k.,bot }\ m.,L nparallel U }$$

The point of this proof is showing that is not possible that there are two lines parallel to line $$U$$ passing through point $$P$$. I have a problem on line 6 when I need to make a substitution instance of PAR 2. The variable used (where I wrote $$l_0$$) need to be “fresh”, i.e. not appear in any undischarged assumptions.

How can I overcome that problem and continue the proof ?

P.D.: rules of inference can be found in Appendix C of this book: http://forallx.openlogicproject.org/forallxyyc.pdf

## unity – (Unity3D) Determine If Ray Intersects Given Rectangle

I’m building a city generator for my game and I want to ensure buildings are never placed in such a way that they overlap roads. Currently I have the system build the roads, then place buildings alongside those roads.

I have the beginning and end points of the roads as Vector3s (only using X and Z, Y is never considered for road/building placement). For buildings, I use the size of their Box Colliders to check if they can fit in a given space (with rotation and scale applied appropriately). I’ve done a fair amount of research for answers on lines intersecting planes, though they always seem to be incredibly hard to follow or just don’t properly apply to my situation (such as determining if the line is coterminous or not). I simply need to know if the line at any point exists within the bounds of the building’s rectangle. I do not need to know where or at what angle.

I also understand that my problem is essentially a 2D math problem, as I’m ignoring Y, and some of the 2D solutions I’ve seen to this would be extremely costly to do in city generation.

Any help would be greatly appreciated.

## python – How to test if a given rectangle intersects with a list of excluded areas?

I have implemented SegmentBisect for 1D segments. Given a list of 1D segments, it constructs a data-structure that defines the excluded regions on the x-axis.

I have some difficulty to extend/use SegmentBisect to create a class that can fast find if a rectangle in the x-y space intersects an apriori list of rectangles.

The 1D solution take O(log(n)) I assume it’s possible to get O(log^2(n))

import bisect

class SegmentBisect():

def isCoordExcluded(self, coordinate):
i = self.excludedIndex(coordinate)
try:
return self.isExcluded(i)
except:
return False

def excludedIndex(self, coordinate):
return bisect.bisect_right(self.segmentBisect, coordinate)

def __init__(self, lineSegments):

lineSegments.sort(key=lambda x:min(x))
self.segmentBisect = ()
self.isExcluded    = ()
for segment in lineSegments:
if type(segment) == range:
segment = range(min(segment), max(segment)+1) # to support input as range
else:
segment = range(min(segment), max(segment))
low  = min(segment)
high = max(segment)+1 # to include b-1 for the excluded segment:(a,b)
lowExcluded  = self.isCoordExcluded(low)
highExcluded = self.isCoordExcluded(high)

if lowExcluded and highExcluded:
continue
elif not lowExcluded and not highExcluded:
self.segmentBisect.extend((low, high))
self.isExcluded.extend((False, True))
elif lowExcluded and not highExcluded:
idx = self.excludedIndex(low)
self.segmentBisect(idx) = max(high,self.segmentBisect(idx))
else:
raise('Error while adding the segment {0} to the bisect array.'.format(range(low,high)))

import unittest
class TestSegmentBisect(unittest.TestCase):
def test_five_segments_three_intersections(self, sbs=None):
if not sbs:
sbs = SegmentBisect(((20,30), (10,3), (2,6), (8,12), (50,100)))

for i in range(-2,2):
self.assertFalse(sbs.isCoordExcluded(i))

for i in range(2,12):
self.assertTrue(sbs.isCoordExcluded(i))

for i in range(20,30):
self.assertTrue(sbs.isCoordExcluded(i))

for i in range(30,50):
self.assertFalse(sbs.isCoordExcluded(i))

for i in range(50,100):
self.assertTrue(sbs.isCoordExcluded(i))

for i in range(100,102):
self.assertFalse(sbs.isCoordExcluded(i))

def test_five_segments_three_intersections_range(self):
sbs = SegmentBisect((range(20,30), range(3,10), range(2,6), range(8,12), range(50,100)))
self.test_five_segments_three_intersections(sbs)