POV-Ray : Newsgroups : povray.general : Need math help : Re: Need math help Server Time
10 Aug 2024 03:19:11 EDT (-0400)
  Re: Need math help  
From: Tor Olav Kristensen
Date: 9 Mar 2000 21:30:25
Message: <38C85D21.FB173E75@hotmail.com>
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] hotmailcom
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.