Prev: Why does this line of code take so long to execute?
Next: Remember the Consolidator by John D'Errico?
From: Bard Romstad on 18 Jul 2010 10:36 > Hi Roger, > Giving it a second look I'm not quite certain what Baris ment after all, but what I am trying to find is how to calculate the signed angle (-pi to pi) between two vectors, A and B, projected onto the vertical plane passing through vector C, viewed from the direction defined by cross(C,[0 0 1]). > To clarify (or confuse): > In my specific problem A and B are surface normals of two neighbouring patches on a 2.5D topographic surface (no caves/overhangs -> normals are always pointing upwards). I want to investigate the convexity of the topographic surface along a given direction (defined by the horizontal component of C). My idea was to do this by finding the angle between A and B (relative to C). Having thought a little more about this I guess a more general formulation of my question is how to find the signed angle (-pi to pi) between two vectors, A and B, projected onto the plane defined by a normal vector N (which in the specific case above was cross(C,[0 0 1])), viewed from the direction of N. Bård
From: Roger Stafford on 18 Jul 2010 13:13 "Bard Romstad" <this.is.not.a.real.address(a)gmail.com> wrote in message <i1v3gj$8rh$1(a)fred.mathworks.com>... > Having thought a little more about this I guess a more general formulation of my question is how to find the signed angle (-pi to pi) between two vectors, A and B, projected onto the plane defined by a normal vector N (which in the specific case above was cross(C,[0 0 1])), viewed from the direction of N. > > Bård - - - - - - - - - - - Yes, that makes sense. I presume when you say, "viewed from the direction of N", you mean in accordance with the right-hand rule: if your right-hand thumb points along the direction of N, then your fingers curl in the direction of positive angle change. And when you say, "signed angle between A and B" you mean the angle measured from the projection of A toward the projection of B but restricted to the interval -pi to +pi. That can be done this way: N = N/norm(N); % Make N a unit vector ang = atan2(dot(cross(A,B),N),dot(cross(A,N),cross(B,N))); Note that this will fail if either A or B is parallel to N, as you would expect, since the projection of that respective vector onto the plane would then be zero and therefore the angle would be undefined. Roger Stafford
From: Bard R. on 18 Jul 2010 14:38 "Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message <i1vcn1$s7p$1(a)fred.mathworks.com>... > "Bard Romstad" <this.is.not.a.real.address(a)gmail.com> wrote in message <i1v3gj$8rh$1(a)fred.mathworks.com>... > > Having thought a little more about this I guess a more general formulation of my question is how to find the signed angle (-pi to pi) between two vectors, A and B, projected onto the plane defined by a normal vector N (which in the specific case above was cross(C,[0 0 1])), viewed from the direction of N. > > > > Bård > - - - - - - - - - - - > Yes, that makes sense. I presume when you say, "viewed from the direction of N", you mean in accordance with the right-hand rule: if your right-hand thumb points along the direction of N, then your fingers curl in the direction of positive angle change. And when you say, "signed angle between A and B" you mean the angle measured from the projection of A toward the projection of B but restricted to the interval -pi to +pi. > > That can be done this way: > > N = N/norm(N); % Make N a unit vector > ang = atan2(dot(cross(A,B),N),dot(cross(A,N),cross(B,N))); > > Note that this will fail if either A or B is parallel to N, as you would expect, since the projection of that respective vector onto the plane would then be zero and therefore the angle would be undefined. > > Roger Stafford This is exactly what I was looking for. And so much more compact than the solution I had put together during the day. It works if A and B are opposite (I had to do an extra check for that as well) and for my application N is by definition never parallell to neither A nor B. Thanx a lot! Bård
From: Roger Stafford on 18 Jul 2010 15:52 "Bard R." <this.is.not.a.real.address(a)gmail.com> wrote in message <i1vhmb$1rq$1(a)fred.mathworks.com>... > This is exactly what I was looking for. And so much more compact than the solution I had put together during the day. It works if A and B are opposite (I had to do an extra check for that as well) and for my application N is by definition never parallell to neither A nor B. > Thanx a lot! > Bård - - - - - - - - - - - - Well, if A and B, or even their projections, are in opposite directions, the outcome can suddenly flip from one extreme to the other depending on rounding. A roundoff one way gets +pi as a result and in the other direction flips the answer over to -pi. I don't see any good way out of that problem. It is more or less inherent in the nature of numerical computation of angles. A digital computer cannot even compute the exact value of pi itself. Roger Stafford
From: Loren_Shure on 19 Jul 2010 08:21 "Roger Stafford" <ellieandrogerxyzzy(a)mindspring.com.invalid> wrote in message news:i1vm13$ok8$1(a)fred.mathworks.com... > "Bard R." <this.is.not.a.real.address(a)gmail.com> wrote in message > <i1vhmb$1rq$1(a)fred.mathworks.com>... >> This is exactly what I was looking for. And so much more compact than the >> solution I had put together during the day. It works if A and B are >> opposite (I had to do an extra check for that as well) and for my >> application N is by definition never parallell to neither A nor B. >> Thanx a lot! >> Bård > - - - - - - - - - - - - > Well, if A and B, or even their projections, are in opposite directions, > the outcome can suddenly flip from one extreme to the other depending on > rounding. A roundoff one way gets +pi as a result and in the other > direction flips the answer over to -pi. I don't see any good way out of > that problem. It is more or less inherent in the nature of numerical > computation of angles. A digital computer cannot even compute the exact > value of pi itself. > > Roger Stafford Have you checked out the function subspace: http://www.mathworks.com/access/helpdesk/help/techdoc/ref/subspace.html ? -- Loren http://blogs.mathworks.com/loren/ http://matlabwiki.mathworks.com/MATLAB_FAQ
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 5 Prev: Why does this line of code take so long to execute? Next: Remember the Consolidator by John D'Errico? |