POV-Ray : Newsgroups : povray.advanced-users : Bug in Knee macro? Server Time
26 Nov 2024 04:44:09 EST (-0500)
  Bug in Knee macro? (Message 1 to 4 of 4)  
From: Rune
Subject: Bug in Knee macro?
Date: 4 Feb 2001 17:03:09
Message: <3a7dd19d$1@news.povray.org>
When rendering the short cyclic animation below it seems to me that there's
a bug in the famous Knee macro. I really need a version that works
perfectly. Can anybody help?

Thanks in advance,

Rune
--
\ Include files, tutorials, 3D images, raytracing jokes,
/ The POV Desktop Theme, and The POV-Ray Logo Contest can
\ all be found at http://rsj.mobilixnet.dk (updated January 28)
/ Also visit http://www.povrayusers.org

---

camera {location <3,0,0> look_at 0 orthographic}
light_source {<3,2,1>*1000, color 1}
background {color rgb 1}

#declare HipPoint    = +0.9*y;
#declare AnklePoint  = -0.4*y + vrotate(0.6*y,360*x*clock);
#declare ThighLength = 1.2;
#declare ShinLength  = 0.8;

#macro Perpendiculize (V1,V2)
   vnormalize(vcross(vcross(V2,V1),V2))
#end
#declare KneeDirection = Perpendiculize(z,AnklePoint-HipPoint);

#macro Knee (pA,pH,lT,lS,vD)
   #local lB=vlength(pA-(pH));
   #if( (lB>lT+lS) | (lT>lB+lS) | (lS>lT+lB) )
      #error "Invalid span lengths.\n"
   #end
   #local tS=(lT+lS+lB)/2;
   #local tA=sqrt(tS*(tS-(lT))*(tS-(lS))*(tS-lB));
   #local tH=tA*2/lB;
   #local vO=vnormalize(pA-(pH));
   #local vF=vnormalize(vcross(vD,vO));
   #local vU=vnormalize(vcross(vO,vF));
   (pH+vO*sqrt((lT)*(lT)-tH*tH)+vU*tH)
#end

#declare KneePoint =
Knee(HipPoint,AnklePoint,ShinLength,ThighLength,KneeDirection);

cylinder {AnklePoint, KneePoint, 0.05 pigment {color <1,0,0>}}
cylinder {HipPoint,   KneePoint, 0.05 pigment {color <0,1,0>}}
torus {0.6, 0.05 rotate 90*z translate -0.4*y}


Post a reply to this message

From: Tor Olav Kristensen
Subject: Re: Bug in Knee macro?
Date: 4 Feb 2001 19:51:20
Message: <3A7DF8B1.C0442574@online.no>
Rune wrote:
> 
> When rendering the short cyclic animation below it seems to me that there's
> a bug in the famous Knee macro. I really need a version that works
> perfectly. Can anybody help?

Can you please describe the problem ?


Not that I suspect this to be the reason for your problem,
but you should compare the capital letters in your macro
call with those in the start of the macro declaration.

Knee( HipPoint, AnklePoint, ShinLength, ThighLength, KneeDirection );
Knee(pA,       pH,         lT,         lS,              vD)


I have put another variant of this macro below
with more descriptive variable names if you want
to look for errors yourself.

-- 
Best regards,

Tor Olav

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


// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =

#macro FindKnee(pAnkle, pHip, ThighLength, ShinLength, vForw)

  #local vLeg = pAnkle - pHip;
  #local dd = vlength(vLeg);
  #if (dd > ThighLength + ShinLength)
    #debug "\n\nError: The ankle is too far away from the hip.\n\n"
  #end // if
  #if (dd < abs(ThighLength - ShinLength))
    #debug "\n\nError: The ankle is too close to the hip.\n\n"
  #end // if
  #local aa =
    (pow(dd, 2) + pow(ThighLength, 2) - pow(ShinLength, 2))/2/dd;
  #local bb = sqrt(pow(ThighLength, 2) - pow(aa, 2));
  #local vRight = vcross(vForw, vLeg);
  #local vFront = vcross(vLeg, vRight);

  (pHip + aa*vnormalize(vLeg) + bb*vnormalize(vFront))

#end // macro FindKnee

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =

// And then a shorter version:

#macro Knee(pA,pH,LT,LS,vD)
  #local vB=pA-pH;
  #local LB=vlength(vB);
  #if(LB>LT+LS|LB<abs(LT-LS))
    #error "\nInvalid span lengths.\n"
  #end
  #local aa=(LB*LB+LT*LT-LS*LS)/2/LB;
  #local bb=sqrt(LT*LT-aa*aa);
  #local vF=vcross(vB,vcross(vD,vB));
  (pH+aa*vnormalize(vB)+bb*vnormalize(vF))
#end

// ===== 1 ======= 2 ======= 3 ======= 4 ======= 5 ======= 6 ======= 7 =


Post a reply to this message

From: Rune
Subject: Re: Bug in Knee macro?
Date: 5 Feb 2001 06:52:31
Message: <3a7e93ff@news.povray.org>
"Tor Olav Kristensen" wrote:
> Can you please describe the problem ?

Sorry. The knee point is not always correctly calculated. In the posted
animation code the length of the thigh is shortened in one part of the
cycle.

> Not that I suspect this to be the reason for your problem,
> but you should compare the capital letters in your macro
> call with those in the start of the macro declaration.
>
> Knee( HipPoint, AnklePoint, ShinLength, ThighLength, KneeDirection );
> Knee(pA,       pH,         lT,         lS,              vD)

Ah yes, I see that I've switched hip point and ankle point and also thigh
length and shin length, but it should make no difference.

> I have put another variant of this macro below
> with more descriptive variable names if you want
> to look for errors yourself.

Your variant doesn't produce the error it seems. Thank you!

To compare the results of yours and John's macro, have a look at the code
below.

Rune
--
\ Include files, tutorials, 3D images, raytracing jokes,
/ The POV Desktop Theme, and The POV-Ray Logo Contest can
\ all be found at http://rsj.mobilixnet.dk (updated January 28)
/ Also visit http://www.povrayusers.org

---

#declare Macro = 1; // 1 = John's macro, 2 = Tor's macro

camera {location <3,0,0> look_at 0 orthographic}
light_source {<3,2,1>*1000, color 1}
background {color rgb 1}

#declare HipPoint    = +0.9*y;
#declare AnklePoint  = -0.4*y + vrotate(0.6*y,360*x*clock);
#declare ThighLength = 1.2;
#declare ShinLength  = 0.8;

#macro Perpendiculize (V1,V2)
   vnormalize(vcross(vcross(V2,V1),V2))
#end
#declare KneeDirection = Perpendiculize(z,AnklePoint-HipPoint);

#if (Macro=1)

#macro Knee (pA,pH,lT,lS,vD)
   #local lB=vlength(pA-(pH));
   #if( (lB>lT+lS) | (lT>lB+lS) | (lS>lT+lB) )
      #error "Invalid span lengths.\n"
   #end
   #local tS=(lT+lS+lB)/2;
   #local tA=sqrt(tS*(tS-(lT))*(tS-(lS))*(tS-lB));
   #local tH=tA*2/lB;
   #local vO=vnormalize(pA-(pH));
   #local vF=vnormalize(vcross(vD,vO));
   #local vU=vnormalize(vcross(vO,vF));
   (pH+vO*sqrt((lT)*(lT)-tH*tH)+vU*tH)
#end

#else

#macro Knee(pA,pH,LT,LS,vD)
  #local vB=pA-pH;
  #local LB=vlength(vB);
  #if(LB>LT+LS|LB<abs(LT-LS))
    #error "\nInvalid span lengths.\n"
  #end
  #local aa=(LB*LB+LT*LT-LS*LS)/2/LB;
  #local bb=sqrt(LT*LT-aa*aa);
  #local vF=vcross(vB,vcross(vD,vB));
  (pH+aa*vnormalize(vB)+bb*vnormalize(vF))
#end

#end

#declare KneePoint =
Knee(HipPoint,AnklePoint,ShinLength,ThighLength,KneeDirection);

cylinder {AnklePoint, KneePoint, 0.05 pigment {color <1,0,0>}}
cylinder {HipPoint,   KneePoint, 0.05 pigment {color <0,1,0>}}
sphere {AnklePoint, 0.1 pigment {color <0,0,2>}}
sphere {HipPoint,   0.1 pigment {color <0,0,2>}}
sphere {KneePoint,  0.1 pigment {color <0,0,2>}}
torus {0.6, 0.05 rotate 90*z translate -0.4*y}


Post a reply to this message

From: John VanSickle
Subject: Re: Bug in Knee macro?
Date: 13 Apr 2001 17:23:32
Message: <3AD76F11.8B287DE5@erols.com>
Rune wrote:
> 
> When rendering the short cyclic animation below it seems to me that
> there's a bug in the famous Knee macro. I really need a version that
> works perfectly. Can anybody help?

Sorry for jumping into this thread this late.

I noticed this bug while crafting "Robotany", and fixed it.  I think I
uploaded the fix, but I can't be sure because I can't reach my site
at the moment.

The new version uses the same algorithm that Tor's uses.

Regards,
John
-- 
ICQ: 46085459


Post a reply to this message

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