Cross Product multi Dim data
조회 수: 17 (최근 30일)
이전 댓글 표시
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
채택된 답변
Roger Stafford
2016년 4월 29일
편집: Roger Stafford
2016년 4월 29일
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
Roger Stafford
2016년 4월 29일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!