Questions tagged [intersection]

Intersection is a term that relates to descriptive geometry and functions. Intersections are points which are included in multiple objects. They are intersections of the object they belong to.

2483 questions
68
votes
14 answers

How to find the intersection point between a line and a rectangle?

I have a line that goes from points A to B; I have (x,y) of both points. I also have a rectangle that's centered at B and the width and height of the rectangle. I need to find the point in the line that intersects the rectangle. Is there a formula…
John Petterson
  • 683
  • 1
  • 5
  • 4
62
votes
2 answers

Filter the elements of a map based on a subset of its keys without iterating through the entire thing

I have a Map and a Set. Is there a way to "intersect" the keys of the map with the set of strings such that only the pairs with the given key remain, without iterating over the entire map? My main concern is performance…
dave
  • 1,607
  • 3
  • 16
  • 20
58
votes
10 answers

How to find the intersection of two graphs

Let 0 <= x <= 1. I have two columns f and g of length 5000 respectively. Now I plot: plt.plot(x, f, '-') plt.plot(x, g, '*') I want to find the point 'x' where the curve intersects. I don't want to find the intersection of f and g. I can do it…
Shiva Prakash
  • 1,849
  • 4
  • 21
  • 25
53
votes
1 answer

Intersection of two string array (ignore case)

I have two arrays: string[] array1 = { "Red", "blue", "green", "black" }; string[] array2 = { "BlUe", "yellow", "black" }; I need only the matching strings in one array (ignoring case). Result should be: string[] result = { "blue", "black" } or {…
Ali
  • 3,545
  • 11
  • 44
  • 63
52
votes
10 answers

Test if two lines intersect - JavaScript function

I've tried searching for a javascript function that will detect if two lines intersect each other. The function will take the x,y values of both the start end points for each line (we'll call them line A and line B). Is to return true if they…
Jarrod
  • 9,349
  • 5
  • 58
  • 73
47
votes
3 answers

Java 8 Lambda - Intersection of Two Lists

I am trying to find intersection of two lists based on some condition and doing some steps. Couldn't find a way to do it (in learning stage) :) Double totalAmount = 0.00d; Double discount = 0.00d; List orderLineEntryList =…
RaceBase
  • 18,428
  • 47
  • 141
  • 202
46
votes
6 answers

Best way to get intersection of keys of two objects?

I have two object literals like so: var firstObject = { x: 0, y: 1, z: 2, a: 10, b: 20, e: 30 } var secondObject = { x: 0, y: 1, z: 2, a: 10, c: 20, d: 30 } I want to get the intersection of the…
Swiffy
  • 4,401
  • 2
  • 23
  • 49
46
votes
8 answers

Efficiently finding the intersection of a variable number of sets of strings

I have a variable number of ArrayList's that I need to find the intersection of. A realistic cap on the number of sets of strings is probably around 35 but could be more. I don't want any code, just ideas on what could be efficient. I have an…
tshred
  • 463
  • 1
  • 4
  • 4
46
votes
4 answers

Python set Union and set Intersection operate differently?

I'm doing some set operations in Python, and I noticed something odd.. >> set([1,2,3]) | set([2,3,4]) set([1, 2, 3, 4]) >> set().union(*[[1,2,3], [2,3,4]]) set([1, 2, 3, 4]) That's good, expected behaviour - but with intersection: >> set([1,2,3]) &…
Bilal Akil
  • 4,716
  • 5
  • 32
  • 52
42
votes
9 answers

3D Line-Plane Intersection

If given a line (represented by either a vector or two points on the line) how do I find the point at which the line intersects a plane? I've found loads of resources on this but I can't understand the equations there (they don't seem to be standard…
jt78
  • 906
  • 2
  • 10
  • 22
42
votes
9 answers

Efficient maths algorithm to calculate intersections

For a game I am developing I need an algorithm that can calculate intersections. I have solved the problem, but the way I have done it is really nasty and I am hoping someone here might have a more elegant solution. A pair of points represent the…
Mitch
41
votes
8 answers

Checking if two cubic Bézier curves intersect

For a personal project, I'd need to find out if two cubic Bézier curves intersect. I don't need to know where: I just need to know if they do. However, I'd need to do it fast. I've been scavenging the place and I found several resources. Mostly,…
zneak
  • 134,922
  • 42
  • 253
  • 328
40
votes
5 answers

Finding Intersection of NSMutableArrays

I have three NSMutableArray containing names that are added to the lists according to different criterieas. Here are my arrays pseudocode: NSMutableArray *array1 = [@"Jack", @"John", @"Daniel", @"Lisa"]; NSMutableArray *array2 = [@"Jack", @"Bryan",…
aeciftci
  • 679
  • 2
  • 6
  • 15
40
votes
6 answers

Set of efficient 3D intersection algorithms

Anyone knows a source, website where I can get some good implementations of 3D intersection algorithms, like intersection of sphere and…
Pythagoras of Samos
  • 3,051
  • 5
  • 29
  • 51
40
votes
4 answers

efficiently knowing if intersection of two list is empty or not, in python

Suppose I have two lists, L and M. Now I want to know if they share an element. Which would be the fastest way of asking (in python) if they share an element? I don't care which elements they share, or how many, just if they share or not. For…
Manuel Araoz
  • 15,962
  • 24
  • 71
  • 95