Cross Product multi Dim data
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Bineet_Mehra
el 29 de Abr. de 2016
Comentada: Bineet_Mehra
el 30 de Abr. de 2016
I have u1 v1 w1(velocity components) volumetric data. Size of u1 is NxNxN (N is 100) and same is true frol v1 and w1.
I have one more case of u2, v2, w2, each one of size NxNxN. both these data sets are obtained from TriScatteredInterp and meshgrid. Basically i plotted streamlines for these two cases and now i want to see how much deviation is there between these streamlines (from case 1 to 2.). I need to find the angle between them at the points given by meshgrid. But cross product wont work (A and B must have at least one dimension of length 3.).. any suggestion ?? Thanks a lot
0 comentarios
Respuesta aceptada
Roger Stafford
el 29 de Abr. de 2016
Editada: Roger Stafford
el 29 de Abr. de 2016
Actually you can use matlab's 'cross' function.
A = cat(4,u1,v1,w1); % Combine the three components in the 4th dimension
B = cat(4,u2,v2,w2); % Ditto
C = cross(A,B,4); % Take the cross products there.
ang = atan2(sqrt(dot(C,C,4)),dot(A,B,4));
This last is taking atan2(norm(cross products),dot products), which is the accurate way of finding angles. The result should be a three dimensional NxNxN array of angles. The angles can range from 0 to pi radians.
4 comentarios
Roger Stafford
el 29 de Abr. de 2016
The array C, like A and B, is four dimensional with the fourth dimension of size 3. Each of those triplets along the fourth dimension are the components of the cross product of the corresponding pair of triplets in A and B. Now when we take dot(C,C,4), that is suddenly three dimensional with each element being the square of the length of the corresponding triplet in C. After we take the square root we have the lengths of each of the triplets in C. That accounts for the expression sqrt(dot(C,C,4)). The quantity dot(A,B,4) is also three dimensional and is the scalar (dot) product of each pair of corresponding triplets in A and B. As you undoubtedly are aware, the length of a cross product equals the product of the lengths of each separate vector times the sine of the angle between them. The scalar (dot) product is equal to the product of their lengths times the cosine of the angle between them. That is what is needed by the function 'atan2'. Its two arguments must be proportional to the sine and cosine, respectively, of the desired angle. Then atan2 will produce that angle. In your case it will produce a three dimensional array of NxNxN of such angles.
Más respuestas (0)
Ver también
Categorías
Más información sobre Multidimensional Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!