cartesian

Cartesian to polar coordinates

爷,独闯天下 提交于 2019-12-23 07:39:56
问题 Take a look at the example here: http://www.brianhare.com/physics/so.html Take a look at console.log where I am using these two main functions: function distanceBetween2pts(x1, y1, x2, y2) { console.log("Particle: ("+x1+","+y1+") Mouse: ("+x2+","+y2+")"); // Pythagoras Theorem // PQ = sqrt( (x2-x1)^2 + (y2-y1)^2 ) var x = (x2-x1); var y = (y2-y1); this.radius = Math.sqrt(x*x + y*y); this.x = x; this.y = y; } function polar2cartesian(R, theta) { this.x = R * Math.cos(theta); this.y= R * Math

Generating all possible combinations of strings

青春壹個敷衍的年華 提交于 2019-12-21 21:07:35
问题 I am trying to generate all possible combinations of a string. e.g. for the list below: a1q5z!H9, b1q5z!H9, c1q5z!H9, d1q5z!H9, a2q5z!H9 ... etc Rather than make lots of nested loops, I thought I would try something clever with MODULO ... but hit a wall. This is the Javascript I have come up with - any pointers to how I might go on? var c = [ ['a', 'b', 'c', 'd'], ['1', '2', '3', '4'], ['q', 'w', 'e', 'r'], ['5', '6', '7', '8'], ['z', 'x', 'c', 'v'], ['!', '"', '£', '$'], ['H', 'J', 'K', 'L']

Spark Unique pair in cartesian product

99封情书 提交于 2019-12-14 04:14:01
问题 I have this: In [1]:a = sc.parallelize([a,b,c]) In [2]:a.cartesian(a).collect() Out[3]: [(a, a), (a, b), (a, c), (b, a), (c, a), (b, b), (b, c), (c, b), (c, c)] I want the following result: In [1]:a = sc.parallelize([1,2,3]) In [2]:a.cartesianMoreInteligent(a).collect() Out[3]: [(a, a), (a, b), (a, c), (b, b), (b, c), (c, c)] Because my calculus return a symetrical matrix (correlation). What is the best way to achieve this ? (No loop) With a, b and c can be anything, even tuple. 回答1: Not sure

Efficient axis-wise cartesian product of multiple 2D matrices with Numpy or TensorFlow

。_饼干妹妹 提交于 2019-12-12 23:06:00
问题 So first off, I think what I'm trying to achieve is some sort of Cartesian product but elementwise, across the columns only. What I'm trying to do is, if you have multiple 2D arrays of size [ (N,D1), (N,D2), (N,D3)...(N,Dn) ] The result is thus to be a combinatorial product across axis=1 such that the final result will then be of shape (N, D) where D=D1*D2*D3*...Dn e.g. A = np.array([[1,2], [3,4]]) B = np.array([[10,20,30], [5,6,7]]) cartesian_product( [A,B], axis=1 ) >> np.array([[ 1*10, 1

Convert image in polar to cartesian coordinates

a 夏天 提交于 2019-12-12 03:55:43
问题 I am trying to convert an image in polar to cartesian coordinates. examples to convert image to polar coordinates do it explicitly - want a slick matrix method I thought using the method used above would be a piece of cake but it really isn't!! If anyone finds an error into my code please let me know! phi=(0:.01:1)*2*pi; r=0:.01:2; psi=r<0.5; psi_c=cos(phi).'*psi; [P R z]=find(psi_c); L=500; X=R.*cos(P); Y=R.*sin(P); Xmin=min(X);Xmax=max(X); Ymin=min(Y);Ymax=max(Y); F=TriScatteredInterp(X,Y,z

Cartesian Products with sets in java

走远了吗. 提交于 2019-12-11 18:55:03
问题 I am trying to create a cartesian product method in java that accepts sets as arguments and returns a set pair. The code I have coverts the argumented sets to arrays and then does the cartesian product but i can't add it back to the set pair that i want to return. Is there an easier way to do this? Thanks in advance. public static <S, T> Set<Pair<S, T>> cartesianProduct(Set<S> a, Set<T> b) { Set<Pair<S, T>> product = new HashSet<Pair<S, T>>(); String[] arrayA = new String[100]; String[]

Create a spiral between two cartesian points in MATLAB

不羁的心 提交于 2019-12-11 04:33:38
问题 Perhaps this is a basic question but I haven't been able to find anything specifically like this and I'm wondering how to do it in the best way. I have two sets of points (x1,y1,z1) and (x2,y2,z2) and I have converted them into polar coordinates. I would like to create a counter-clockwise helix of decreasing radius to reach the second point. I would also like to specify how many revolutions it takes. All of the examples I have seen are two points on the x axis and going clockwise. Any

Shortest Path distance between points given as X-Y coordinates

我与影子孤独终老i 提交于 2019-12-10 13:51:29
问题 I am currently working on a project that has a vector containing X and Y coordinates for approximately 800 points. These points represent an electric network of lines. My goal is to compute the shortest distance Path between a Point A and Point B that can be or can not be located along the path given by the vectors containing the X-Y coordinates of the electric lines. I have read about the Dijkstra Algorithm but since i am not that much familiar with it, I am not sure if I should go in that

Why does my JavaScript function accept three arrays, but not an array containing three arrays?

拈花ヽ惹草 提交于 2019-12-10 12:16:49
问题 function product() { return Array.prototype.reduce.call(arguments, function(as, bs) { return [a.concat(b) for each (a in as) for each (b in bs)] }, [[]]); } arr4=[['4','4A','4B'],['16D','15D'],['5d','5e']]; alert(product(['4','4A','4B'],['16D','15D'],['5d','5e']); The above works but the following don't work: arr4=[['4','4A','4B'],['16D','15D'],['5d','5e']]; alert(product(arr4); Thanks for suggestions 回答1: You can have either one or the other; otherwise it's poorly defined. (Unless you want

Compute distance in Cartesian Coordinate System in Mathematica

北城以北 提交于 2019-12-07 06:04:18
问题 Analyzing Eye-movements on a screen, I set my origin to the bottom left corner of it (Hard to modify at that point). Trying to compute distance between some points and the center of the screen I use the simple formula displayed below. Problem is that using this in conditional statement, it gets ugly. Sqrt[ ( (fixationX - centerX)^2 + (fixationY - centerY)^2 ) ] Is there a way to customize Norm to compute distance between points and not between a point and the origin ? Or in my case, set the