|
![](/i/fill.gif) |
Tor Olav Kristensen wrote:
> Hi Sebastian
>
> I like problems like the one you presented here, so I have tried
> to do some thinking.
But I thought wrong!
The macro did only work when the two radiuses were equal.
Here is another try. Se macro below.
Tor Olav
mailto:tor### [at] hotmail com
http://www.crosswinds.net/~tok/tokrays.html
#macro TorusConnect(SP, SMaR, SMiR, EP, EMaR, EMiR)
// SP: S Point (Center of one torus)
// SMaR: S Major Radius
// SMiR: S Minor Radius
// EP: E Point (Center of other torus)
// EMaR: E Major Radius
// EMiR: E Minor Radius
// And suffixes; v: Vector, p: Point, R: Radius
// Note: Origo, SP and EP may not be colinear
#local Upv = vcross(EP, SP);
#local Dv = EP - SP;
#local Outv = vnormalize(vcross(Dv, Upv));
#local SMaRv = SMaR*Outv;
#local EMaRv = EMaR*Outv;
#local SMaRp = SP + SMaRv;
#local EMaRp = EP + EMaRv;
#local Slopev = EMaRp - SMaRp;
#local SlopeNv = vcross(Slopev, Upv);
#local dp = vlength(Slopev);
#local dMiR = SMiR - EMiR;
#if (dMiR = 0)
#local c = SMiR;
#local Bv = Nullv;
#else
#local b = dMiR*dMiR/dp; // Because dp/SMiR = SMiR/b
#local Bv = ((dMiR > 0) ? 1 : -1)*b*vnormalize(Slopev);
#local c = sqrt(dMiR*dMiR - b*b); // Because dMir*dMir = b*b + c*c
#end
#local Cv = c*vnormalize(SlopeNv);
#local SMiRv = SMiR*vnormalize(Bv + Cv);
#local EMiRv = EMiR*vnormalize(Bv + Cv);
#local SMiRp = SMaRp + SMiRv;
#local EMiRp = EMaRp + EMiRv;
#local EndSp = SP + vproject(SMiRv, Dv);
#local EndEp = EP + vproject(EMiRv, Dv);
#local EndSR = vlength(SMiRp - EndSp);
#local EndER = vlength(EMiRp - EndEp);
/* // Remove this line for debugging
#local sr = 0.3;
#local Storus = torus { SMaR, SMiR }
#local Etorus = torus { EMaR, EMiR }
#local Storus = object { vtilt(Storus, Dv) translate SP }
#local Etorus = object { vtilt(Etorus, Dv) translate EP }
union {
sphere { SP , sr }
sphere { SMaRp, sr }
sphere { SMiRp, sr }
sphere { EndSp, sr }
object { Storus }
sphere { EP , sr }
sphere { EMaRp, sr }
sphere { EMiRp, sr }
sphere { EndEp, sr }
object { Etorus }
*/ // Remove this line for debugging
cone { EndSp, EndSR, EndEp, EndER }
/* // Remove this line for debugging
}
*/ // Remove this line for debugging
#end
Post a reply to this message
|
![](/i/fill.gif) |