intersection

How to intersect two polygons?

允我心安 提交于 2019-11-26 10:22:09
问题 This seems non-trivial (it gets asked quite a lot on various forums), but I absolutely need this as a building block for a more complex algorithm. Input : 2 polygons (A and B) in 2D, given as a list of edges [(x0, y0, x1, y2), ...] each. The points are represented by pairs of double s. I do not know if they are given clockwise, counter-clockwise or in any direction at all. I do know that they are not necessarily convex. Output : 3 polygons representing A, B and the intersecting polygon AB.

Intersect with a custom IEqualityComparer using Linq

依然范特西╮ 提交于 2019-11-26 10:01:53
问题 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

Efficient intersection of two List<String> in Java?

人走茶凉 提交于 2019-11-26 09:46:25
问题 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? 回答1: You can use retainAll method: columnsOld.retainAll (columnsNew); 回答2: Since retainAll won't touch the argument collection, this would be faster: List<String> columnsOld = DBUtils.GetColumns(db, TableName); List<String> columnsNew = DBUtils.GetColumns

Efficient maths algorithm to calculate intersections

放肆的年华 提交于 2019-11-26 09:18:06
问题 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

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

半城伤御伤魂 提交于 2019-11-26 09:17: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

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

只谈情不闲聊 提交于 2019-11-26 09:02:53
问题 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 implementation that I\'m about to start coding but want to hear some other ideas. Currently, just thinking about my solution, it looks like I should have an asymptotic run-time of Θ(n 2 ). Thanks for any help! tshred Edit: To clarify, I really just

Intersect Two Lists in C#

我只是一个虾纸丫 提交于 2019-11-26 08:26:50
问题 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] 回答1: 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

Finding Intersection of NSMutableArrays

纵然是瞬间 提交于 2019-11-26 08:20:20
问题 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\", @\"Barney\", @\"Lisa\",@\"Penelope\",@\"Angelica\"]; NSMutableArray *array3 = [@\"Jack\", @\"Jerome\", @\"Dan\", @\"Lindsay\", @\"Lisa\"]; I want to find a fourth array which includes the intersection of those three arrays. In this case

Circle-circle intersection points

匆匆过客 提交于 2019-11-26 08:03:04
问题 How do I calculate the intersection points of two circles. I would expect there to be either two, one or no intersection points in all cases. I have the x and y coordinates of the centre-point, and the radius for each circle. An answer in python would be preferred, but any working algorithm would be acceptable. 回答1: Intersection of two circles Written by Paul Bourke The following note describes how to find the intersection point(s) between two circles on a plane, the following notation is

Intersecting two dictionaries in Python

你。 提交于 2019-11-26 07:38:31
问题 I am working on a search program over an inverted index. The index itself is a dictionary whose keys are terms and whose values are themselves dictionaries of short documents, with ID numbers as keys and their text content as values. To perform an \'AND\' search for two terms, I thus need to intersect their postings lists (dictionaries). What is a clear (not necessarily overly clever) way to do this in Python? I started out by trying it the long way with iter : p1 = index[term1] p2 = index