Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: How to rotate a (3-D) line in a plane by an angle of theta about the point of origin ? Date: Sun, 22 May 2011 23:21:04 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 21 Message-ID: <irc5p0$t0t$1@newscl01ah.mathworks.com> References: <ir62ul$31b$1@newscl01ah.mathworks.com> <ir7245$1ca$1@newscl01ah.mathworks.com> <ir8rqu$hkl$1@newscl01ah.mathworks.com> <ir8vbe$ppj$1@newscl01ah.mathworks.com> <ir95nq$be6$1@newscl01ah.mathworks.com> <ir9mcc$kmm$1@newscl01ah.mathworks.com> <irbt3g$8el$1@newscl01ah.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: www-01-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: newscl01ah.mathworks.com 1306106464 29725 172.30.248.46 (22 May 2011 23:21:04 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Sun, 22 May 2011 23:21:04 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:728116 "Mahsa " <newsreader@mathworks.com> wrote in message <irbt3g$8el$1@newscl01ah.mathworks.com>... > Thanks for the tip on the vector notation for the ray and normal. I was a bit confused because I was working with points and line equations rather than vector notation. It is much easier this way, thanks. > It was an interesting suggestion to skip the calculation of theta, however, the formulation is not straight forward for me. I do have increasing speed in my simulation (water+solid to air bubble), so my r is greater than one. If we assume that the vectors are normalized, could we define the new vector without having to separately calculate theta of refraction (although it is not a big deal)? thanks. - - - - - - - - - - That code I gave you will in fact work for r greater than one. Also you do not have to normalize P and N for it to work properly. It is designed to always give the norm of Q equal to that of P. However to get meaningful results you do need to restrict its use to cases where the quantity within the square root, t1^2+t2*dot(N,N), is non-negative. When this is zero that is the extreme case where Q would be bent over so far as to be orthogonal to the surface normal - in other words the outgoing ray would travel tangent to the surface. Beyond that, no refraction can occur - it becomes total reflection. This nicely corresponds to a complex result for the square root in the code. In your statement, "the formulation is not straight forward for me", are you asking how the expression was derived? It is not difficult. Let the vector Q be expressed as a linear combination of P and N: Q = a*P + b*N which forces Q to lie in the same plane as P and N. Then impose two conditions on Q: 1) that the ratio of the orthogonal distance of the endpoint of Q from the line of N to the orthogonal distance of P to that line be r (Snell's Law,) and 2) that the norm of Q be equal to the norm of P. The first requirement implies that coefficient a must equal r since the ratio of the lengths of vectors cross(Q,N) and cross(P,N), being the ratios of the sines of the theta angles, must be equal to r. The second requirement gives rise to a quadratic equation in b with two solutions in which only one of them is valid for the refraction problem, and is the one used in the code I gave you. (You will note that I rationalized the numerator of this quadratic solution to provide better computation accuracy when r is close to one.) It is equivalent to the geometry problem of drawing a circle in the plane of N and P with radius norm(P). Vectors N and P are based at the circle's center and the endpoint of P would therefore be a point on the circle. We are to move in or out from the endpoint of vector P along the line of the vector by the ratio r, and from the resulting point draw a line parallel to the line of N until we meet the circle. This will actually occur for two points, but only the nearer point to the endpoint of N is the solution we seek. The "total reflection" case noted above corresponds to moving so far out on the line of P with an r greater than one that a line parallel to N would miss the circle altogether. Roger Stafford