intersection

how to get the intersection of two JSON arrays using jq

不羁的心 提交于 2019-12-11 00:08:06
问题 Given arrays X and Y (preferably both as inputs, but otherwise, with one as input and the other hardcoded), how can I use jq to output the array containing all elements common to both? e.g. what is a value of f such that echo '[1,2,3,4]' | jq 'f([2,4,6,8,10])' would output [2,4] ? I've tried the following: map(select(in([2,4,6,8,10]))) --> outputs [1,2,3,4] select(map(in([2,4,6,8,10]))) --> outputs [1,2,3,4,5] 回答1: A simple and quite fast (but somewhat naive) filter that probably does

Points of intersection of vector with cone

China☆狼群 提交于 2019-12-10 18:34:58
问题 I have a Vector A defined as : (Ao+t∗Ad) I also have a Cone with vertex (cone tip) V , axis direction D , base radius R and height H . How can I find the points of intersection between the vector and cone? I'm using glm for maths. Here's a simple illustration: 回答1: I'm not handling all the cases where the ray intersects the cone, such as if the ray lies on the cone or if the ray is tangent to the cone, because it's not necessary in my case, but here's the solution I ended up with: std::array

Finding intersection of two matrices in Python within a tolerance?

一世执手 提交于 2019-12-10 15:16:47
问题 I'm looking for the most efficient way of finding the intersection of two different-sized matrices. Each matrix has three variables (columns) and a varying number of observations (rows). For example, matrix A: a = np.matrix('1 5 1003; 2 4 1002; 4 3 1008; 8 1 2005') b = np.matrix('7 9 1006; 4 4 1007; 7 7 1050; 8 2 2003'; 9 9 3000; 7 7 1000') If I set the tolerance for each column as col1 = 1 , col2 = 2 , and col3 = 10 , I would want a function such that it would output the indices in a and b

How to determine point/time of intersection for ray hitting a moving triangle?

筅森魡賤 提交于 2019-12-10 11:35:19
问题 I have a deforming triangle, whose vertices all move between t0 and t1. I am shooting a ray toward the triangle. The ray doesn't hit the triangle at t0 or t1, but somewhere within that interval of time. How do I calculate the exact point of intersection for the ray, and at what time (between t0 and t1) that the ray hits the triangle? Here's an image that hopefully helps illustrate the question better: 来源: https://stackoverflow.com/questions/43771759/how-to-determine-point-time-of-intersection

Check android.graphics.path intersection with itself

廉价感情. 提交于 2019-12-10 03:57:45
问题 I'd like to check if (and if yes, where the collission is(x,y) - just for highlighting) a path does intersect itself. It would also be very interesting how i do check if a path does intersect with another path. Here is a screenshot to better explain what i mean: http://i.stack.imgur.com/JrEmN.png 回答1: The simplest way is to check if any line segment intersects with any other line segment. A line segment is made up of pairs of adjacent points in the path. A path with 10 points has 9 line

How can I obtain the largest set of rows that share a common set of at least 4 columns?

故事扮演 提交于 2019-12-09 19:36:39
问题 I have a matrix containing gene names and sample numbers. Each row is a logical vector indicating the samples in which a gene was detected. Genes must appear in a minimum of 4 samples out of 8 to make it this far (still be in the matrix). i.e., all genes in this matrix appear in 4 or more samples. Sample1 Sample2 Sample3 Sample4 Sample5 Sample6 Sample7 Sample8 gene1 TRUE FALSE TRUE TRUE TRUE FALSE FALSE FALSE gene2 FALSE TRUE FALSE TRUE FALSE TRUE TRUE FALSE gene3 TRUE TRUE FALSE TRUE FALSE

Determine if two lines intersect

微笑、不失礼 提交于 2019-12-09 19:35:03
问题 I've seen many postings here on stackoverflow, which are discussing this topic. I took a solution from stackoverflow, but I couldn't find the posting. It was to say: If two lines are intersecting, then the crossproduct produces for the left and the right side two different results. One positive and one negative. Otherwise both have the same sign. So far it is okay. The used formula is, where AB is one line and CD another. dotproductleft = (B.x-A.x) (C.y-B.y)-(B.y-A.y) (C.x-B.x)

Getting Union, Intersection, or Difference of Sets in C++

守給你的承諾、 提交于 2019-12-09 17:10:05
问题 I have a couple questions about how to use C++ sets (std::set) Is there a way to get the union, intersection, or difference of two C++ sets? (It's pretty easy to write my own functionto do that but I wanted to know if there was a built in function for it) Can C++ sets be used as keys in a map? 回答1: Use the set_difference(), set_union(), set_intersection() and set_symmetric_difference() functions. Sets and maps support any key type that can compare. By default this means the type has operator<

How do I do an integer list intersection while keeping duplicates?

故事扮演 提交于 2019-12-09 10:06:59
问题 I'm working on a Greatest Common Factor and Least Common Multiple assignment and I have to list the common factors. Intersection() won't work because that removes duplicates. Contains() won't work because if it sees the int in the second list it returns all matching ints from the first list. Is there a way to do an Intersection that is not Distinct? edit: sorry for not providing an example, here is what I meant: if I have the sets: {1, 2, 2, 2, 3, 3, 4, 5} {1, 1, 2, 2, 3, 3, 3, 4, 4} I would

3D Ray-Quad intersection test in java

自闭症网瘾萝莉.ら 提交于 2019-12-09 06:15:46
问题 In 3D space I am trying to determine if a ray/line intersects a square and if so, the x and y position on the square that it intersects. I have a ray represented by two points: R1 = (Rx1, Ry1, Rz1) and R2 = (Rx2, Ry2, Rz2) And the square is represented by four vertices: S1 = (Sx1, Sy1, Sz1), S2 = (Sx2, Sy2, Sz2), S3 = (Sx3, Sy3, Sz3) and S4 = (Sx4, Sy4, Sz4). I’ve found lots of algebraic equations for this online but none seem to fit this problem exactly. Ideally I would like the answer in