POV-Ray : Newsgroups : povray.advanced-users : Bug in Knee macro? : Re: Bug in Knee macro? Server Time
29 Jul 2024 20:12:37 EDT (-0400)
  Re: Bug in Knee macro?  
From: Tor Olav Kristensen
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

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