intersection

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

筅森魡賤 提交于 2019-12-17 23:15:59
问题 This question already has answers here : Test if lists share any items in python (9 answers) Closed 3 years ago . 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 example, in this case L = [1,2,3,4,5,6] M = [8,9,10] I should get False, and here: L = [1,2,3,4,5,6] M = [5,6,7] I should get True. I hope

The intersection point between a spline and a line

自作多情 提交于 2019-12-17 22:55:25
问题 I'm trying to find a way to calculate the intersection between a b-spline and a straight line. So far Google hasn't been much help. 回答1: The most efficient algorithm that I've heard of is called Bezier clipping. Here's a book chapter on curve and spline intersection (pdf). 回答2: A pure mathematical approach: Transform the spline and the line so that the line lies on the X axis. Calculate the points on the spline where Y = 0 (depends on the order of the spline). Transform these points back to

Swift: Is there an easy way to draw shapes and detect whether they intersect? [duplicate]

孤人 提交于 2019-12-17 19:44:27
问题 This question already has an answer here : Swift: detecting intersection from sprite kit SKShapeNode drawings (1 answer) Closed 5 years ago . Is there an easy way to draw shapes in Swift (preferrably with Sprite-Kit) and then detect if and where they intersect? Like here's an intersecting shape: 回答1: If this consists of a series of line segments, one can adapt Martin R's answer to UIBezierPath intersect to not only detect intersections, but to also identify where the intersections are: func

Python list intersection with non unique items

随声附和 提交于 2019-12-17 19:19:53
问题 I have two strings and I would like to have the intersection on them including duplicate items: str_a = "aabbcc" str_b = "aabd" list(set(str_a) & set(str_b)) >> "ab" I would like to have it return: >> "aab" Any ideas? 回答1: Multisets are implemented in python 2.7 or later as (mutable) Counter objects. You can perform many of the same operations as you can for sets, such as union, intersection, difference (though counts can become negative), etc.: from collections import Counter as mset

Trying to optimize line vs cylinder intersection

北战南征 提交于 2019-12-17 18:48:07
问题 My brain has been melting over a line segment-vs-cylinder intersection routine I've been working on. /// Line segment VS <cylinder> // - cylinder (A, B, r) (start point, end point, radius) // - line has starting point (x0, y0, z0) and ending point (x0+ux, y0+uy, z0+uz) ((ux, uy, uz) is "direction") // => start = (x0, y0, z0) // dir = (ux, uy, uz) // A // B // r // optimize? (= don't care for t > 1) // <= t = "time" of intersection // norm = surface normal of intersection point void

Python - matplotlib: find intersection of lineplots

ぐ巨炮叔叔 提交于 2019-12-17 15:56:28
问题 I have a probably simple question, that keeps me going already for quiet a while. Is there a simple way to return the intersection of two plotted (non-analytical) datasets in python matplotlib ? For elaboration, I have something like this: x=[1.4,2.1,3,5.9,8,9,23] y=[2.3,3.1,1,3.9,8,9,11] x1=[1,2,3,4,6,8,9] y1=[4,12,7,1,6.3,8.5,12] plot(x1,y1,'k-',x,y,'b-') The data in this example is totaly arbitrary. I would now like to know if there is a simple build in function that I keep missing, that

Calculation of intersections between line segments

余生长醉 提交于 2019-12-17 15:40:49
问题 There's a lot of questions about intersections between line segments here at stackowerflow and here is one more! Sorry, but I need help to understand how to calculate intersections. I have read several of the questions here and looked at several examples on other websites, but I'm still confused and don't get it! I don't like to copy and paste code without how things work. So far I know that I'm going to compare the points of each line segments like Ax, Ay, Bx, By, Cx, Cy, Dx, Dy. Could

Compute the area of intersection between a circle and a triangle?

北战南征 提交于 2019-12-17 10:29:09
问题 How does one compute the area of intersection between a triangle (specified as three (X,Y) pairs) and a circle (X,Y,R)? I've done some searching to no avail. This is for work, not school. :) It would look something like this in C#: struct { PointF vert[3]; } Triangle; struct { PointF center; float radius; } Circle; // returns the area of intersection, e.g.: // if the circle contains the triangle, return area of triangle // if the triangle contains the circle, return area of circle // if

finding point of intersection in R

不打扰是莪最后的温柔 提交于 2019-12-17 05:05:11
问题 I have 2 vectors: set.seed(1) x1 = rnorm(100,0,1) x2 = rnorm(100,1,1) I want to plot these as lines and then find the intersection points of the lines, also if there are multiple points of intersection then I want to locate each of them. I have come across a similar question,and tried to solve this problem using spatstat , but I was not able to convert my combined data frame containing both vector values to psp object . 回答1: If you literally just have two random vectors of numbers, you can

How to calculate the intersection of two sets? [duplicate]

陌路散爱 提交于 2019-12-17 02:33:51
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Efficiently finding the intersection of a variable number of sets of strings Say, have two Hashset, how to calculate the intersection of them? Set<String> s1 = new HashSet<String>(); Set<String> s2 = new HashSet<String>(); S1 INT S2 ? 回答1: Use the retainAll() method of Set: Set<String> s1; Set<String> s2; s1.retainAll(s2); // s1 now contains only elements in both sets If you want to preserve the sets, create a