Re: I don't want an elliptic sun.... (advanced patch placement in 3d)
Status: Alpha
Brought to you by:
cwalther
From: Christian W. <cwa...@gm...> - 2008-06-23 19:07:44
|
Andrea Viarengo wrote: > I tried the code that follows, you can move the sun using arrow, > and you can notice distorsion with elevation>45 > > The distorsion is due to the system used to rotate patches, as > the first rotation (along x) also amends the orientation of > the second axis of rotation (along y). > > and I believe that, in this case, the problem will disappear if you > rotate first along the Y axis and then along the axis X, (perhaps > the ideal would be able to choose the order of rotation axis ...) Yes, you're right. Swapping the default order to Y first, then X would be easy. I wonder if there are any other applications that would be made more difficult by that? I agree that the application of orienting a patch to the viewer given azimuth and elevation is a useful one and should be made easy. Doing this would break backwards compatibility with 0.2.7, however. (I guess we could still do it, as there probably aren't many people using X and Y rotation yet.) Implementing an arbitrarily specifiable rotation order would be a bit more involved (though it may be worth it - I'll look into it). We could also introduce another property "anglex2", so that rotation would happen in the order anglex, angley, anglex2, angle. Opinions, anyone? In the current system, you can't get away without doing some trigonometry. Going through the cartesian coordinates seems easiest: x = cos el sin az = sin dl y = sin el = cos dl sin bz z = -cos el cos az = -cos dl cos bz Here's what I've come up with, modifying your example, and it seems to work well: function setpos(p,dis,az,el) local nz=-math.cos(math.rad(az))*math.cos(math.rad(el)) local nx=math.sin(math.rad(az))*math.cos(math.rad(el)) local ny=math.sin(math.rad(el)) local dl = math.deg(math.asin(nx)) local bz = math.deg(math.atan2(ny, -nz)) pipmak.printinplace("az ", az, " el ", el, " bz ", bz," dl ",dl) p:move{nx=nx, ny=ny, nz=nz, anglex=bz, angley=-dl } pipmak.setviewdirection(az, el) end -Christian |