plot,wolfram-mathematica,intersection

You can use the Epilog option to add graphics primitives to a plot: intersections = {x, y} /. NSolve[y == -(x - 2)^2 + 4 && y == x/(x + 1), {x, y}]; Plot[{-(x - 2)^2 + 4, x/(x + 1)}, {x, 0, 4}, Filling -> {1 -> {{2}, {White,...

javascript,three.js,line,intersection,mesh

From Three.js documentation: Ray(origin, direction) origin -- Vector3 The origin of the Ray. direction -- Vector3 The direction of the Ray. So if you have pointA and pointB that are the clicks of the user, you can: (pseudo code) origin = pointA direction = (pointB-pointA).normalize() myRay = THREE.Ray(origin, direction) You...

ruby,arrays,performance,set,intersection

Gentlemen! Start your engines! Below is a benchmark comparison of the three answers given to date. My main reason for doing this was to evaluate the relative efficiency of @Stefan's solution, which uses a regex. I had the impression that regex's are often relatively inefficient, but as you can see...

It turns out that the issue was not the algorithm, but an error elsewhere in my code. It took me a while to figure it out, but once I did the algorithm works perfectly.

The intersect function may be of use for your case. I am not sure how you use the tables, but the code below should let you find the indices of the intersection for each DateN vector. Once you have the indices, you can rebuild a global table which only incorporate...

linq,hashtable,union,intersection,difference

Well, it's gonna be rather hard to use IEnumerable<T> extensions methods if you use an Hashtable instead of a Dictionary<TKey, TValue>. Because an Hashtable is not a generic type. So there's no Hashtable.Union available, nore Hashtable.Keys.Union. You would have to do something like hashtable1.Keys.Cast<int>().Union(hashtable2.Keys.Cast<int>()); But... what will happen if keys...

c#,order,geometry,polygon,intersection

iterate through the lines first in an outer loop, then for each line get the 2 points in the specific order you want. Modify your code to put the two found itxns in temporary list, instead of directly into intersections collection - then, in between the inner and outer loop...

algorithm,indexing,intersection,polyline

Assuming that the polylines are nondegenerate, to decide multidimensional polyline containment, you can partition the segments by slope–y-intercept pairs and solve several 1D problems. To solve the 1D problem, use a sweepline algorithm, processing the segment endpoints in sorted order and maintaining two flags, one for whether the sweepline intersects...

three.js,intersection,onmouseover

I advise you to stick to the same order, much like in the examples on the site threejs.org: // global variables var camera; var scene; ... window.onload = function() { init(); render(); //final output } function init() { ... } function render() { ... } I took the liberty to...

javascript,arrays,union,intersection,set-theory

filter() can at least hide the loops for you: A = [1,2,3,4,5]; B = [1,2,3,6,7]; C = intersection(A, B); D = arrayDiff(A, C); E = arrayDiff(B, C); console.log(JSON.stringify(C)); console.log(JSON.stringify(D)); console.log(JSON.stringify(E)); function intersection(a, b) { return a.filter( function(el) { return b.indexOf(el) >= 0; } ); } function arrayDiff(a, b) { return...

python,numpy,intersection,euclidean-distance,line-intersection

Basic algorithm: pretend that you have lines, so oriented that A lies to the left of B. Find closest point as normal. If the point is between A and B, you're done. If it's to the left of A, the closest point is A. If the point is to the...

matlab,computational-geometry,intersection

Use the parametric equation of the line segment, P = (1-t) A + t B, with 0<=t<=1. Find the intersections between the polygon edges and the line of support of the segment, expressing the position of the intersection in terms of t (momentarily ignore the constraint on t). You will...

java,gis,polygon,intersection,concave

Well I figured it out. I took the vertex list for the intersection polygon (blue), iterated through each pair of point, cast each line segment in the two original polygons as LineSegment2D objects and used the .contains method to check if each pair of points was in one of the...

Say you want the distance DE to be a given L. Your points {D} and {E} are {D} = {B} + x * {a} {E} = {B} + x * {c} where {a} is the normalised vector BA and {c} is the normalised vector BC. (These vectors have to be...

One way would be: >>> l1 = ['a', 'b', 'c', 'd', 'e', 'c', 'd', 'f'] >>> l2 = ['c', 'd'] >>> [range(i,i+len(l2)) for i in xrange(len(l1)-len(l2)+1) if l2 == l1[i:i+len(l2)]] [[2, 3], [5, 6]] >>> ...

algorithm,computational-geometry,intersection,intervals

The idea to assign values is correct. You just need to sort intervals by their minumum value(in increasing order). That is, the solution looks like this: Build a segment tree(with -infinity values in all nodes). Process all intervals in sorted order. For each interval, just assign its value(no matter what...

python,arrays,numpy,intersection

You could do it as shown below. If a and b get large, this is going to need lots of memory (on the order of the product of the sizes of a and b). Maybe you could loop over into small-enough chunks of b if that's a problem. import numpy...

You did not post any actual question. I guess you want to perform the task in your title, faster than you currently do it. I guess slowness is due to your summary worksheet having too many formulas, which are recalculated upon each change. If so, your solution would be either:...

arrays,mongodb,intersection,aggregation-framework

There are a couple of ways to do this using the aggregation framework Just a simple set of data for example: { "_id" : ObjectId("538181738d6bd23253654690"), "movies": [ { "_id": 1, "rating": 5 }, { "_id": 2, "rating": 6 }, { "_id": 3, "rating": 7 } ] }, { "_id" :...

intersection,dfa,deterministic,automaton

To the best of my knowledge, there's no "direct" algorithm that accomplishes this. You can do this by minimizing the two input DFAs, computing their Cartesian product (which produces another DFA, by the way, not an NFA), then minimizing the result. It's not strictly necessary to minimize the two input...

java,if-statement,intersection,difference

You are missing opening bracket ({) after if: if ("y" != null ) So the following closing bracket actually ends the method main(args); } // method ended here else{ break; } and your else is no mans land, which compiler does not like....

r,data.frame,bioinformatics,intersection

Try this example: #dummy data, with real data we would do: res.DESeq2_rn <-row.names(res.DESeq2) res.DESeq2_rn <- letters[1:4] res.edgeR_rn <- letters[3:8] res.limma_rn <- letters[c(1,3,8,10)] #get counts res <- table(c(res.DESeq2_rn, res.edgeR_rn, res.limma_rn)) res # a b c d e f g h j # 2 1 3 2 1 1 1 2 1...

It looks like you have the Mapping Toolbox. The simplest way to achieve the intersection points between two polygons is to use the polyxpoly function. The prototype looks like this: [xi,yi] = polyxpoly(x1, y1, x2, y2); x1 and y1 are the x and y coordinates that define the polygon of...

math,graphics,geometry,game-physics,intersection

As @NicoSchertler suggested in a comment, a solution is to take each triangle and clip it on all the planes. If there are no points left (or under 3 points, so it is not a triangle), the triangle intersects the polyhedron. This seems to work well.

three.js,intersection,bounding-box

If you're looking to roll your own, I'd recommend reading Separating Axis Theorem for Oriented Bounding Boxes by Johnny Huynh. Here is a collision detection method given two orientated bounding boxes I made for a game I was working on. It isn't in ThreeJS but it should be fairly straight...

c++,performance,vector,stl,intersection

Your algorithm is O(n2) in the number of elements (assuming that the size of both vectors is approximately equal to n). Here is an O(n) algorithm: Create an std::unordered_set<int> Put all items of vector A into the set Go through all items of vector B, checking that they are present...

function intersection(a, b) { var result = []; for (var i = 0; i < a.length; i++){ if (a[i].total == 90 && a[i].tip == 0) { result.push(a[i]); } } for (var i = 0; i < b.length; i++){ if (b[i].total == 90 && b[i].tip == 0) { result.push(b[i]); } }...

algorithm,math,geometry,polygon,intersection

You could just iterate over the edges of your polygon and check whether one of them intersect your square. If one does then you are done. Otherwise just test whether either 1) the center of the square belongs to the polygon 2) an arbitrary point in the polygon belongs to...

python,string,list,set,intersection

You can use flatten function of compiler.ast module to flatten your sub-list and then apply set intersection like this from compiler.ast import flatten A=[['[email protected]'], ['[email protected]'], ['[email protected]'], ['[email protected]'], ['[email protected]']] B=[['[email protected]'], ['[email protected]']] a = flatten(A) b = flatten(B) common_elements = list(set(a).intersection(b)) common_elements ['[email protected]'] ...

r,nlp,intersection,text-mining

I guess another similar way would by just to use a simple match string <- strsplit(c(t1, t2), "\\s+") # similar to @Richard length(na.omit(match(string[[2]], string[[1]]))) ## [1] 7 Or maybe lapply length(unlist(lapply(string[[2]], intersect, string[[1]]))) ## [1] 7 ...

You could move the player, then check to see if it is in a wall and, if it is, undo the move (or better, calculate a new location as the result of a move, check it, and if it is good, only then move the player there). Note that this...

c++,performance,opengl,3d,intersection

on GPU I would do it like this: set view to cones origin directing outwards covering the bigest circle slice for infinite cone use max Z value of mesh vertexes in view coordinate system clear buffers draw mesh but in fragment shader draw only pixels intersecting cone |fragment.xyz-screen_middle|=tan(cone_ang/2)*fragment.z read z-buffer...

suppose your line segment goes between points a and b. treat it as a parametric equation. first, let d = b - a so your line segment is described by: a + td for all real numbers between 0 and 1 and the infinite line that contains it is described...

collections,neo4j,cypher,union,intersection

You're right, this can be solved using REDUCE. Inside the reduce you need to check if the current element already exists in the accumulator and conditionally amend it: MATCH (a)-[:NT*]->(b), (a)-[:CODE]-(c), (b)-[:CODE]-(d) WHERE a.btqty = 0 WITH a.termid AS termid, a.maxlen AS maxlen, REDUCE(uniqueCodes=[], x in COLLECT(DISTINCT c.code) + COLLECT(DISTINCT...

sprite-kit,intersection,touchesbegan

I suggest you use the didBeginContact: instead of intersectsNode. In MyScene you can set it up like this: @implementation MyScene { BOOL playerBlockContact } - (void)didBeginContact:(SKPhysicsContact *)contact { uint32_t collision = (contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask); if (collision == (CNPhysicsCategoryPlayer | CNPhysicsCategoryBlock)) { playerBlockContact = true; NSLog(@"Contact"); } } - (void)didEndContact:(SKPhysicsContact *)contact...

c#,image,picturebox,intersection

Pixel-perfect collision detection can be slow, so many 2D games elect to use bounding boxes like you've already done. To improve accuracy you could use multiple bounding objects (e.g. more boxes, circles, or convex polygons) which resemble the shape of opaque regions in your bitmaps. If you still want pixel-perfect...

java,libgdx,intersection,rectangles

Taken from here and here, that is because of Rectangle.overlaps: public boolean overlaps (Rectangle r) { return x < r.x + r.width && x + width > r.x && y < r.y + r.height && y + height > r.y; } This code assumes that the widths/heights of the rectangles...

java,algorithm,geometry,complexity-theory,intersection

You can not find all intersection points of n circles in the plane in O(n log n) time because every pair of circles can have up to two distinct intersection points and therefore n circles can have up to n² - n distinct intersection points and hence they can not...

javascript,arrays,algorithm,intersection,set-intersection

The first challenge is to make the function correct. Once it's correct, we can worry about the speed. There are a few things which could trip-up a function like this: NaN Bad limits Repeated numbers Only 1 input array (or none at all) Your original function can handle repeated numbers,...

This is what the code is doing. Every point P in the segment AB can be described as: P = A + u(B - A) for some constant 0 <= u <= 1. In fact, when u=0 you get P=A, and you getP=B when u=1. Intermediate values of u will...

java,algorithm,polygon,intersection

Polygons 1, 2 and 3 are the same thing. :-) You can get Area Gamma by using intersect(). Then you can subtract() Area Gamma from Polygon A to get Area Alpha (the part of A that's outside Gamma), and subtract() Gamma from B to get Beta (the part of B...

python,math,collision-detection,intersection

There's no way to do this that's simpler than the obvious one: find the infinite plan that contains your polygon determine the point where the line intersects that plane determine whether this point is within the polygon All but the very rare line will intersect the infinite plan somewhere, so...

javascript,3d,three.js,intersection

You can take a look at http://www.realtimerendering.com/intersections.html. Even though the site is from 2011 the intersection algorithms have not changed in the last years. From the demo it seems that once the polyhedrons are placed in the cube, they don't move. So the SAT algorithm would not be the best...

I simply wasn't recalculating the normal after the transformation. Adding the calculateNormal(); statement at the end of the Transform function solved the problem.

intersection,regular-language,context-free-language

No, your statement is not true. Consider the following counter-example: L = {0n1n2n | n > 0}, P = T = Ø. Clearly we have L ∩ P = L ∩ Ø = Ø = T, and Ø is both regular and context-free. Note it is well-known that L is...

algorithm,computational-geometry,intersection

I don't think there's much out of the ordinary you can use here. The calculation of the intersection points is fairly straightforward. With the x direction left to right, and y bottom to top, let's say that we the bottom horizontal line is at y1 and the top at y2,...

As was pointed out in the comments, you are not finding an intersection rather you are finding if a single entity of original is present in target. That being said, your first example is O(N) because the range is O(N) and the map lookup is O(1). Your second example is...

java,math,intersection,rectangles

Perhaps this method offers what you're looking for public List<Point> getIntersects(Rectangle2D a, Rectangle2D b) { if (!a.intersects(b)) return null; List<Point> points = new ArrayList<Point>(); double ax = a.getX(); double ay = a.getY(); double aw = a.getWidth(); double ah = a.getHeight(); double bx = b.getX(); double by = b.getY(); double bw...

android,intersection,framelayout,rect

You are Checking the Views locations before they got measured and being drawn to the screen. the call firstView.getWidth is probably 0. you can check it by logging. add TreeObserver or something like: secondView.addOnLayoutChangeListener. by the way i didn't check if your intersect algorithm is correct, only notified you about...

python-2.7,intersection,random-forest

Normalization Start by first normalizing the data in the range 0 to 1. This can be done using the following formula. Norm(e) = (e - Emin) / (Emax - Emin) for each value e in each vector. (I don't know how to put math symbols in here or I would.)...

algorithm,geometry,line,polygon,intersection

When you intersect two sections, that dont have an intersection point, your function should return null. For example: in your first picture, the 4th line from the bottom does not intersect the left or the top edge of the rectangle, it only intersects the bottom and the right edges. If...

matlab,if-statement,matrix,intersection

Use ismember with the 'rows' option to find the desired rows, and then use that as an index to build the result: ind = ismember(A(:,2:4), B(:,2:4), 'rows'); C = A(ind,:); I have assumed that a row of A is selected if its last three columns match those of any row...

c++,computational-geometry,intersection,rectangles

You don't care where the rectangles are vertically. You can project everything onto the x-axis and then solve the corresponding 1-dimensional problem: you have a set of intervals and you want to know which overlap with a given interval. This is exactly what an interval tree is does: https://en.wikipedia.org/wiki/Interval_tree...

It seems that GetWidenedPathGeometry and GetOutlinedPathGeometry manipulate the PathGeometry in a way, that the intersection gets empty. After removing these and just call GetFlattenedPathGeometry makes my code to run fine as expected. Here is the fixed code: Path p1; // filled with a polygon Path p2; // filled with another...

3d,javafx,intersection,javafx-3d

As @jdub1581 suggests, a ray is just a geometric vector, so in order to find a list of triangles intersected by this vector we need to solve problems of the kind 'line intersects plane' and 'line intersects plane within the triangle borders'. Let's assume we have a TriangleMesh, and we...

Since you want any game liked by two or more friends, I suggest counting the number of appearances of each game, and then returning those that appear more than once. You can use collections.Counter to do the counting easily: import collections def friendslike(network,user): games = collections.Counter() for friend in get_connections(network,...

full-text-search,xquery,intersection,marklogic,cts-search

As a footnote to Dave's good advice, another alternative would be to use search:parse() instead of search:search() to convert the second search request to a cts:query before running the cts:search(). http://docs.marklogic.com/search:parse?q=search:parse&v=8.0&api=true Then, add the cts:query() generated search:parse() to the list of subqueries within the existing cts:and-query() and run a single...

ruby-on-rails,ruby,arrays,hash,intersection

simple as that: user1.connections & user2.connections if you want only by the id key (other attributes are different) intersection = user1.connections.map{|oh| oh[:id]} & user1.connections.map{|oh| oh[:id]} user1.connections.select {|h| intersection .include? h[:id] } hope it helps!...

I like to use the igraph package for this type of problem because it's easy to think of the rows as edges in a graph and you are looking for all the connected chunks. my.mat = matrix(data = c(1,4,2,5,7,2,3,6,3,8), ncol = 2, byrow=T) library(igraph) class(my.mat)<-"character" gg <- graph.edgelist(my.mat, directed=T) vset...

postgresql,postgis,intersection

If the two points (or any number of points) are in a Multipoint you can use ST_Contains(Linestring, Multipoint) which will return true if and only if no points of B lie in the exterior of A, and at least one point of the interior of B lies in the interior...

I found out the origin of the problem: in the working script, I was using Orbitcontrols to transform the mesh; in the non-working script, I was transforming the mesh myself and it seems the normals were not updated. What happened is that the origin point was correct but the normal...

java,string,union,intersection

The absolutely most basic way: loop through the first string, check for its containment in the second. It looks like your union and intersect shouldn't have duplicates (if they can this is a much harder problem). /** Returns the union of the two strings, case insensitive. Takes O( (|S1| +...

Just check if the distances of the point from the three centers are less of all the three radius. EDIT: homework? I should not have answered :/...

binary-search-tree,intersection,box,bounding

I would suggest you to use a segment tree. Have a look at these slides: http://algo.kaust.edu.sa/Documents/cs372l07.pdf you are particularly looking for a solution to stabbing queries in higher dimensions (slide 25)...

java,geometry,intersection,numeric

Here's a more numerically stable way of getting the intersection (note that it's actually the intersection of two lines... it seems like your original code didn't check if the intersection was within the segment either): double rX = rayBX - rayAX; double rY = rayBY - rayAY; double sAX =...

Try lapply(df[,1:3], function(x) is.na(intersect(x[df$group=='1'], x[df$group=='2']))) Or Map(function(x,y) is.na(intersect(x,y)), df[df$group=='1',-4], df[df$group=='2', -4]) If you have many groups, lapply(df[,1:3], function(x) is.na(Reduce(`intersect`,split(x, df$group)))) data df <- structure(list(V1 = c("B", "B", "B", "A", "A", "A"), V2 = c("C", "C", "C", "C", "A", "A"), V3 = c("-", "C", "C", "A", "A", "A" ), group =...

As mentioned in the comments, you can apply the traditional algorithm of the intersection of lines (this for example) between all the component lines of the polygons. For example: def line_intersection(line1, line2): xdiff = (line1[0][0] - line1[1][0], line2[0][0] - line2[1][0]) ydiff = (line1[0][1] - line1[1][1], line2[0][1] - line2[1][1]) def det(a,...

Since you're using your second list like a multi-set, let's make that explicit in the type: intersections :: Ord a => [a] -> MultiSet a -> [[a]] The only intersection of a list and an empty multi-set is the empty list intersections _ m | M.null m = [[]] There's...

javascript,arrays,intersection,array-intersect

You need to add the indices to your result; function intersect(first, second) { var temp = []; for(var i = 0; i < first.length; i++){ for(var k = 0; k < second.length; k++){ if(first[i] == second[k]){ temp.push([i, k]); // push i and k as an array } } } return...

Start thinking in reverse problem, two intervals, that, mathematically, can be described as [amin,amax] and [bmin,bmax] do not overlap iff (amin > bmax or bmin> amax). So, by simple reverse of boolean expressions, these intervals overlap iff: (amin <= bmax and bmin <= amax).