POV-Ray : Newsgroups : povray.general : Need math help Server Time
10 Aug 2024 01:19:21 EDT (-0400)
  Need math help (Message 1 to 10 of 16)  
Goto Latest 10 Messages Next 6 Messages >>>
From: Sebastian Strand
Subject: Need math help
Date: 9 Mar 2000 12:08:58
Message: <38c7daaa@news.povray.org>
I've been trying to create a macro that would seamlessly connect two
toruses, just like John VanSickle's Connect macro does for spheres. I can't
seem to get it right, however, so I'd be very grateful if someone with more
math skills than me could help me.

Here's something to work with:
#macro TorusConnect(SP,SMaR,SMiR,EP,EMaR,EMiR)
  #local D=vlength(EP-SP);

  #local Rd=(SMaR+SMiR)-(EMaR+EMiR);
  #local D2=sqrt(D*D-Rd*Rd);

  cone { SP+(EP-SP)/D*(SMiR-EMiR)*(SMaR+SMiR)/D, (SMaR+SMiR)*D2/D,
EP+(EP-SP)/D*(SMiR-EMiR)*(SMaR+SMiR)/D, (EMaR+EMiR)*D2/D }
#end

This, obviously, doesn't work but it does come quite close; it just leaves a
tiny edge at the connection point.








Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Need math help
Date: 9 Mar 2000 15:57:31
Message: <38C80F21.14B82B67@hotmail.com>
Hi  Sebastian

I like problems like the one you presented here, so I have tried
to do some thinking.

I have not seen John VanSickle's Connect macro, but I think that
I understand your problem anyway. I have tried to figure it out by
examining your variable names:

(I did however not understand your description of what the problem
with your macro was.)

Correct me if I'm wrong:

You have two toruses that are parallel to each other.
The centres of these are at two given locations (some distance apart).
And you want to connect the "outsides" of these with a cone.

So if I this is your problem, then I have a suggestion for a solution.
Se my POV-ray file below.

(I have tried to make it easy to understand, and because of this it
became quite long. Abut about half of it can be removed if you don't
need my comments, debug macros and objects)

I have tried to solve the problem with vector math.
My solution is not perfect, because if the centres of both your toruses
lies on a line through origo, then my solution will not work.
(If I have time I'll might try to remove this weakness.)

(And because I didn't understand what the problem with your macro
was, I don't know if my macro is any better than yours.)


Regards,

Tor Olav Kristensen

mailto:tor### [at] hotmailcom
http://www.crosswinds.net/~tok/tokrays.html


Sebastian Strand wrote:

> I've been trying to create a macro that would seamlessly connect two
> toruses, just like John VanSickle's Connect macro does for spheres. I can't
> seem to get it right, however, so I'd be very grateful if someone with more
> math skills than me could help me.
>
> Here's something to work with:
> #macro TorusConnect(SP,SMaR,SMiR,EP,EMaR,EMiR)
>   #local D=vlength(EP-SP);
>
>   #local Rd=(SMaR+SMiR)-(EMaR+EMiR);
>   #local D2=sqrt(D*D-Rd*Rd);
>
>   cone { SP+(EP-SP)/D*(SMiR-EMiR)*(SMaR+SMiR)/D, (SMaR+SMiR)*D2/D,
> EP+(EP-SP)/D*(SMiR-EMiR)*(SMaR+SMiR)/D, (EMaR+EMiR)*D2/D }
> #end
>
> This, obviously, doesn't work but it does come quite close; it just leaves a
> tiny edge at the connection point.
>







// =============================================================
//
// Connecting two torus-"outsides" with a cone
//
// Copyright 2000 by Tor Olav Kristensen
//
// =============================================================

#version 3.1;

#include "colors.inc"

// =============================================================

// Some useful constants

#declare Origo = <0, 0, 0>;
#declare Nullv = <0, 0, 0>;
#declare Unitv = <1, 1, 1>;

// =============================================================
// Just some of my macros

/* // Remove this line for debugging

#macro vCos(UU, VV)
// Returns cosinus of the angle between two vectors

  (vdot(UU, VV)/(vlength(UU)*vlength(VV)))

#end // macro vCos


#macro vangle(UU, VV)
// Returns the angle in radians between two vectors
// 0 <= returned angle < pi

  acos(vCos(UU, VV))

#end // macro vangle


#macro VectorAngles(Vector)
// Returns two angles.
// The first is the angle between Vector and the Y-axis
// The second is the angle between the projection
// of Vector to the XZ-plane and the X-axis

  #local VAngles = Nullv;
  #if (vlength(Vector) > 0)
    #local VAngles = y*vangle(Vector, y);
    #if (VAngles.y > 0)
      #local Sign = 1;
      #if (Vector.z < 0)
        #local Sign = -1;
      #end
      #local VAngles = VAngles + Sign*x*vangle(Vector*(x+z), x);
    #end
  #end // if

  VAngles

#end // macro VectorAngles


#macro vtilt(Thing, TVector)
// Returns the object Thing "tilted" in the
// direction of TiltVector

  #local RotateAngles = VectorAngles(TVector);

  object {
    Thing
    rotate  degrees(RotateAngles.x)*y
    rotate -degrees(RotateAngles.y)*z
    rotate -degrees(RotateAngles.x)*y
  }

#end // macro vtilt

*/ // Remove this line for debugging


#macro vproject(UU, VV)
// Projection of the vector UU in the direction
// of the vector VV.

  ((VV)*vdot(UU, VV)/vdot(VV, VV))

#end // macro vproject


#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 = vnormalize(vcross(Slopev, Upv));

  #local SMiRv = SMiR*SlopeNv;
  #local EMiRv = EMiR*SlopeNv;

  #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


#declare CenterPoint1 = <1, 4, 2>;
#declare MajorRadius1 = 5;
#declare MinorRadius1 = 0.5;

#declare CenterPoint2 = <2, 0, 3>;
#declare MajorRadius2 = 2;
#declare MinorRadius2 = 1;


object {
  TorusConnect(CenterPoint1, MajorRadius1, MinorRadius1,
               CenterPoint2, MajorRadius2, MinorRadius2)
  pigment { color Yellow }
}


#declare PlaneNormal = vnormalize(vcross(CenterPoint1, CenterPoint2));

/* // Remove this line for debugging
plane { PlaneNormal, 0 pigment { color White } }
*/ // Remove this line for debugging

// =============================================================

background { color Grey }

light_source { 1000*PlaneNormal, White }

camera {
  location 15*PlaneNormal
  look_at Origo
}

// =============================================================


Post a reply to this message

From: David Fontaine
Subject: Re: Need math help
Date: 9 Mar 2000 19:03:37
Message: <38C83B18.2B0E74BE@faricy.net>
#macro TorusConnect(p1,mj1,mn1,p2,mj2,mn2)
   #local Dist = sqrt(pow(p1.x-p2.x,2)+pow(p1.y-p2.y,2)+pow(p1.z-p2.z,2));
   #local Ang1 = atan2((mn1+mj1-mn2-mj2)/Dist,1);
   #local Ang2 = asin((mn1-mn2)/sqrt(pow(Dist,2)+pow(mn1+mj1-mn2-mj2,2)));
   cone { p1+vnormalize(p2-p1)*mn1*sin(Ang1+Ang2),mj1+mn1*cos(Ang1+Ang2)
          p2+vnormalize(p2-p1)*mn2*sin(Ang1+Ang2),mj2+mn2*cos(Ang1+Ang2)
   }
#end
If you want the math behind it I can give it to you :-)
And if you want a second cone differenced out of it to smoothly connect the
interior as well, most of the work is already done.

--
___     _______________________________________________
 | \     |_          <dav### [at] faricynet> <ICQ 55354965>
 |_/avid |ontaine        http://www.faricy.net/~davidf/

"The only difference between me and a madman is that I'm not mad." -Dali


Post a reply to this message

From: John VanSickle
Subject: Re: Need math help
Date: 9 Mar 2000 19:27:56
Message: <38C843DB.427C43AA@erols.com>
Sebastian Strand wrote:
> 
> I've been trying to create a macro that would seamlessly connect two
> toruses, just like John VanSickle's Connect macro does for spheres. I
> can't seem to get it right, however, so I'd be very grateful if
> someone with more math skills than me could help me.

Question:  Do the torii share the same axis?

If the answer to is yes, the macro goes like this:

#macro TorusConnect(StartPoint,StartMajorRadius,StartMinorRadius,
  EndPoint,EndMajorRadius,EndMinorRadius)

#local pS=StartPoint;
#local pE=EndPoint;
#local rSJ=StartMajorRadius;
#local rSN=StartMinorRadius;
#local rEJ=EndMajorRadius;
#local rEN=EndMinorRadius;
#local sL1=vlength(pE-pS);
#local vA=vnormalize(pE-pS);

#local sL2=vlength(<sL1,rEJ-rSJ,0>);

#local sL3=sqrt(sL2*sL2-(rEN-rSN)*(rEN-rSN));

#local sC1=sL1/sL2;
#local sS1=(rSJ-rEJ)/sL2;

#local sC2=sL3/sL2;
#local sS2=(rSN-rEN)/sL2;

#local xS=rSJ+(sC1*sC2-sS1*sS2)*rSN;
#local yS=(sC1*sS2+sC2*sS1)*rSN;

#local xE=rEJ+(sC1*sC2-sS1*sS2)*rEN;
#local yE=sL1+(sC1*sS2+sC2*sS1)*rEN;

cone { pS+vA*yS,xS,pS+vA*yE,xE }

#end

I've tested it and it appears to work.  Note that it makes a solid
connector, with no hole in the middle to connect the holes in the torii.

There's no error-checking, so don't give it any strange parameters.

I'll probably toss this into the Thoroughly Useful Macros file,
probably once I get the connecting hole added.

Hope this helps,
John
-- 
ICQ: 46085459


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Need math help
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

From: David Fontaine
Subject: Re: Need math help
Date: 9 Mar 2000 23:28:56
Message: <38C87945.38325391@faricy.net>
Poor little me, trying to carve out a name for myself in the wonderous field
of macros, and everyone has to go and use VanSickle's...
Well I see yours is nice and lengthy compared to mine ;-)

--
___     _______________________________________________
 | \     |_          <dav### [at] faricynet> <ICQ 55354965>
 |_/avid |ontaine        http://www.faricy.net/~davidf/

"The only difference between me and a madman is that I'm not mad." -Dali


Post a reply to this message

From: Sebastian Strand
Subject: SV: Need math help
Date: 10 Mar 2000 06:17:48
Message: <38c8d9dc@news.povray.org>
> Poor little me, trying to carve out a name for myself in the wonderous
field
> of macros, and everyone has to go and use VanSickle's...
> Well I see yours is nice and lengthy compared to mine ;-)

Well, thanks to all three of you that presented a solution. I will now
proceed to try and decide which one to use, probably by testing which macro
parses quickest  :)








Post a reply to this message

From: Sebastian Strand
Subject: SV: Need math help
Date: 10 Mar 2000 08:56:08
Message: <38c8fef8@news.povray.org>
"David Fontaine" <dav### [at] faricynet> wrote:
> If you want the math behind it I can give it to you :-)
> And if you want a second cone differenced out of it to smoothly connect
the
> interior as well, most of the work is already done.

I tried your macro, but it seems that the radius of the cone is slightly
smaller than it should be. There is a tiny visible edge at the connection
point when using highlights, and that same edge does not occur with
VanSickle's version.








Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: SV: Need math help
Date: 10 Mar 2000 13:05:47
Message: <38C93865.F5FE5F14@hotmail.com>
Hi

Sebastian Strand wrote:

> Well, thanks to all three of you that presented a solution. I will now
> proceed to try and decide which one to use, probably by testing which macro
> parses quickest  :)

Try this:

#macro TorusConnect(SP,SMaR,SMiR,EP,EMaR,EMiR)

  #local a=EP-SP;
  #local b=SMaR-EMaR;
  #local c=SMiR-EMiR;
  #local d=vdot(a,a);
  #local e=d+b*b;
  #local f=sqrt(d);
  #local g=sqrt(e-c*c);
  #local h=(f*g-c*b)/e;
  #local i=(f*c+g*b)/e;
  #local j=a/f;

  cone { SMiR*i*j+SP,SMiR*h+SMaR,(EMiR*i+f)*j+SP,EMiR*h+EMaR }

#end // macro TorusConnect

Tor Olav

mailto:tor### [at] hotmailcom
http://www.crosswinds.net/~tok/tokrays.html


Post a reply to this message

From: David Fontaine
Subject: Re: SV: Need math help
Date: 10 Mar 2000 18:23:20
Message: <38C98325.4BF2CDEC@faricy.net>
Sebastian Strand wrote:

> I tried your macro, but it seems that the radius of the cone is slightly
> smaller than it should be. There is a tiny visible edge at the connection
> point when using highlights, and that same edge does not occur with
> VanSickle's version.

$%&%$&#!!!!!

--
___     _______________________________________________
 | \     |_          <dav### [at] faricynet> <ICQ 55354965>
 |_/avid |ontaine        http://www.faricy.net/~davidf/

"The only difference between me and a madman is that I'm not mad." -Dali


Post a reply to this message

Goto Latest 10 Messages Next 6 Messages >>>

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