Most Aligned Child Joint

hello,
im trying to write the following script and am a bit stuck:

Given a single joint name - the script will return a list of its immediate children.
The list will be ordered based on the closeness of alignment of each joint to the parent joint-with those closest to the parent joints axis being at the top of the list.
If two child joints are aligned exactly along the parents axis\vector of alignment- then the nearer of the two will be higher in the list.

ok..
so ive written the main part of this script- it works out the main axis of alignment of the parent joint-
from this i can assume that a good normalised vector will be 1 in that particular axis (this is assuming the local rot axis points down a specified axis completyely in x,y or z- which it should..).

It then works out the vectors from the parent joint to each of the children.
So all i need to do is sort the children based on this info- ie the nearer to 1 that each of the child joints relevant axis lies-in terms of its normalised vector..the higher in the list they should be returned- thus the closer to the parents vector\axis they are..

But now im really stuck with the actual ordering bit- i just cannot work out how to use this info to resort the original list..can anyone help?does anyone understand? or is my explanation confusing?

i dabbled with a "bubble sort" method but it just didnt seem to work...

thanks

Sure but boublesort is slow but here goes sorts 2 pairs

CODE
proc sortStringByNumSLOW(float $num[], string $str[]){
$swapped=1;
$size=size($str);
while($swapped){
  $swapped = 0;
  for($i=0;$i<$size-1; $i++){
            if ($num[$i] > $num[$i+1]){
              $temp=$num[$i];
              $temp2=$num[$i+1];
              $num[$i]=$temp2;
              $num[$i+1]=$temp;
              $tempS=$str[$i];
              $tempS2=$str[$i+1];
              $str[$i]=$tempS2;
              $str[$i+1]=$tempS;
              $swapped=1;
            }
        }
    }
}

Usage, sorts $string array by $number array:
CODE
$numbersf={1.0,2.0,0.0,-0.5};
$string={"one","two","zero","minus point five"};
sortStringByNumSLOW($numbersf,$string);
print $string;

results in:
CODE
minus point five
zero
one
two

NOTE: arrays are allways passed as reference in mel

PS. if you need to distace metric be sure to take the absolute of it into number array to sort with

cheers joojaa- u must be permanently attached to a machine! (but im glad you are...

anyhow- ive done it another way- by just returning a single string rather than an array for the purpose i need-which makes things a whole lot easier..doing something like this:

CODE
        for ($i=0; $i< `size $Jchild`; ++$i)
        {    
            float $largestAxisSoFar;
            if($i == 0)
                {
                $alignedJoint = $Jchild[0];
                $largestAxisSoFar = $mainAxisUnit[$i];
                }
            else
                {
                    if($mainAxisUnit[$i] > $largestAxisSoFar)
                    {
print ($Jchild[$i]+" axis of "+$mainAxisUnit[$i]+" is bigger than "+$Jchild[$i-1]+" of "+ $mainAxisUnit[$i-1]+"\n");
                    $alignedJoint = $Jchild[$i];
                    $largestAxisSoFar = $mainAxisUnit[$i];
                    }
                }
        }

return $alignedJoint;

But now another question..

say a joint has 2 children- and one is perfectly aligned along its axis but far away and the other is slightly of that axis but much nearer..well the normalised vector of the parent to that second child is actually closer to 1 in the important axis than the other more aligned child..

this is annoying and means my script will return the wrong result- any ideas on how i can get a better indication of "alignedness"?

thanks

QUOTE(tarticus @ 10/13/06, 04:27 PM) [snapback]249907[/snapback]
cheers joojaa- u must be permanently attached to a machine! (but im glad you are...

well i monitor about 7 feeds constantly in the bacground (my computers have constantly 7 rss feeds comming in and i have about 12 windows on average opena at a time)

Hi still stuck on this:

anybody got any other ideas on how to find the most "aligned with" child joint of a joint..assuming you know the joint axis of the parent joint...?

i am doing this:
getting normalised vectors for each child joint between them and the parent-
normalising the results using unit-
isolating only the number or axis that corresponds to the parent joints known local rotation axis-
making this number positive if it is negative-
finding the biggest value of this number from all of the child joints-
and matching this number aganst its owner and returning the owner as the "most aligned".

i am getting -near to-but incorrect results

You dont wantto recalculate the unit velues but write them to the second array and use the 2 array sorting fuctor. its faster and easier.

So do thsi pseudocode

childnode[]
value[]
for each in childnode{
value[size(value)]=child.Axisvalue
}
sortStringByNumSLOW(value,childnode) // reveres ethe comparasion

Offcoure if yu just want the max use a extra container to keep the maximum in and dont manipulate the indexes

just do

max=0
maxnode
for each in child{
val=calc childs value
if max < val{
max=val
maxnode=each
}
}