intersection

Java: Is there an easy, quick way to AND, OR, or XOR together sets?

你说的曾经没有我的故事 提交于 2019-11-27 05:48:58
问题 That is, if I had two or more sets, and I wanted to return a new set containing either: All of the elements each set has in common (AND). All of the elements total of each set (OR). All of the elements unique to each set. (XOR). Is there an easy, pre-existing way to do that? Edit: That's the wrong terminology, isn't it? 回答1: Assuming 2 Set objects a and b AND(intersection of two sets) a.retainAll(b); OR(union of two sets) a.addAll(b); XOR either roll your own loop: foreach item if(a.contains

Intersection of two string array (ignore case)

两盒软妹~` 提交于 2019-11-27 03:01:53
问题 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 { "BlUe", "black" }; 回答1: How about an Enumerable.Intersect and StringComparer combo: // other options include StringComparer.CurrentCultureIgnoreCase // or StringComparer.InvariantCultureIgnoreCase var results = array1.Intersect(array2, StringComparer

Distance from point to line on Earth

那年仲夏 提交于 2019-11-27 02:28:02
问题 I need something as simple as "Subject 1.02: How do I find the distance from a point to a line?" But that works with Lon/Lat. 回答1: We'll start with some assumptions: We'll model the figure of the earth as an oblate spheroid. By "line" we mean the minor arc of a great circle. We are looking for a highly accurate solution (for the suggested model) So, rephrasing your question: Given three earth-surface points - p0, p1 and p2, find an earth-surface point on the minor arc of the great circle

Intersect with a custom IEqualityComparer using Linq

↘锁芯ラ 提交于 2019-11-27 02:14:19
Long story short: I have 2 collections of objects. One contains good values (Let's call it "Good"), the other default values (Mr. "Default"). I want the Intersect of the Union between Good and Default, and Default. In other words: Intersect(Union(Good, Default), Default). One might think it resolves as Default, but here is where it gets tricky : I use a custom IEqualityComparer. I got the following classes : class MyClass { public string MyString1; public string MyString2; public string MyString3; } class MyEqualityComparer : IEqualityComparer<MyClass> { public bool Equals(MyClass item1,

Intersect Two Lists in C#

时光怂恿深爱的人放手 提交于 2019-11-27 01:55:28
I have two lists: List<int> data1 = new List<int> {1,2,3,4,5}; List<string> data2 = new List<string>{"6","3"}; I want do to something like var newData = data1.intersect(data2, lambda expression); The lambda expression should return true if data1[index].ToString() == data2[index] You need to first transform data1, in your case by calling ToString() on each element. Use this if you want to return strings. List<int> data1 = new List<int> {1,2,3,4,5}; List<string> data2 = new List<string>{"6","3"}; var newData = data1.Select(i => i.ToString()).Intersect(data2); Use this if you want to return

Efficient intersection of two List<String> in Java?

ε祈祈猫儿з 提交于 2019-11-27 01:47:27
Question is simple: I have two List List<String> columnsOld = DBUtils.GetColumns(db, TableName); List<String> columnsNew = DBUtils.GetColumns(db, TableName); And I need to get the intersection of these. Is there a quick way to achieve this? Roman You can use retainAll method: columnsOld.retainAll (columnsNew); Since retainAll won't touch the argument collection, this would be faster: List<String> columnsOld = DBUtils.GetColumns(db, TableName); List<String> columnsNew = DBUtils.GetColumns(db, TableName); for(int i = columnsNew.size() - 1; i > -1; --i){ String str = columnsNew.get(i); if(

Objective-C check if subviews of rotated UIViews intersect?

家住魔仙堡 提交于 2019-11-27 01:24:52
问题 I don't know where to start with this one. Obviously CGRectIntersectsRect will not work in this case, and you'll see why. I have a subclass of UIView that has a UIImageView inside it that is placed in the exact center of the UIView: I then rotate the custom UIView to maintain the frame of the inner UIImageView while still being able to perform a CGAffineRotation. The resulting frame looks something like this: I need to prevent users from making these UIImageViews intersect, but I have no idea

2d game : fire at a moving target by predicting intersection of projectile and unit

陌路散爱 提交于 2019-11-27 00:03:53
Okay, this all takes place in a nice and simple 2D world... :) Suppose I have a static object A at position Apos, and a linearly moving object B at Bpos with bVelocity, and an ammo round with velocity Avelocity... How would I find out the angle that A has to shoot, to hit B, taking into account B's linear velocity and the speed of A's ammo ? Right now the aim's at the current position of the object, which means that by the time my projectile gets there the unit has moved on to safer positions :) First rotate the axes so that AB is vertical (by doing a rotation) Now, split the velocity vector

Efficient maths algorithm to calculate intersections

时光怂恿深爱的人放手 提交于 2019-11-27 00:03:17
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 end points of a line drawn between them. Given two pairs of points, do the drawn lines intersect, and if so, at what point? So for example call the lines (A.x, A.y)-(B.x, B.y) and (C.x, C.y)-(D.x, D.y) Can anyone think of a solution? A solution in any language will do. Edit: A point I should have made clearer, the algorithm must return false if the

finding point of intersection in R

耗尽温柔 提交于 2019-11-26 22:35:32
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 . If you literally just have two random vectors of numbers, you can use a pretty simple technique to get the intersection of both. Just find all points where x1 is above x2 , and