Path: news.mathworks.com!not-for-mail From: "Mahsa " <newsreader@mathworks.com> 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 20:53:04 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 23 Message-ID: <irbt3g$8el$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> Reply-To: "Mahsa " <newsreader@mathworks.com> NNTP-Posting-Host: www-04-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: newscl01ah.mathworks.com 1306097584 8661 172.30.248.35 (22 May 2011 20:53:04 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Sun, 22 May 2011 20:53:04 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 2882983 Xref: news.mathworks.com comp.soft-sys.matlab:728102 "Roger Stafford" wrote in message <ir9mcc$kmm$1@newscl01ah.mathworks.com>... > "Roger Stafford" wrote in message <ir95nq$be6$1@newscl01ah.mathworks.com>... > > Yes I misunderstood what angle you meant by theta. As I understand it now, if we again regard the normal N as pointing inward from the surface, the angle theta is to be measured from this normal toward, and in the same plane as, the incident ray P. In that case the refracted vector Q would be: > > > > Q = cross(P,N); > > Q = (cos(theta)*N + sin(theta)*cross(N,Q/norm(Q)))/norm(N); > > > > which is a very different formula. > > > > Roger Stafford > - - - - - - - - > In case you wish to bypass the calculation of theta, you can compute Q directly. Let r be the ratio of the outer index of refraction to the inner index, let P be the vector of the incoming ray, and N be the inward pointing normal direction. Then do this: > > t1 = r*dot(P,N); > t2 = dot(P,P)*(1-r^2); > Q = r*P + t2/(sqrt(t1^2+t2*dot(N,N))+t1)*N; > > If the quantity within the square root is negative, you have an r greater than one, (that is the velocity increases,) and an impossible combination of the P and N vectors. > > Roger Stafford 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.