Getting Midpoint using array(?)
- 
 THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED On 22/06/2006 at 05:08, xxxxxxxx wrote: User Information: 
 Cinema 4D Version: 9.1+
 Platform: Windows ; Mac OSX ;
 Language(s) : C.O.F.F.E.E ;--------- 
 I need some help understanding using arrays.
 What I'd like to do is using the selected points in a PointSelectionTag.
 Add those points positions and divide by the amount of points to get a mid position.I come as far as the code below, I get the indexes and corresponding positions,but cannot get the grips of using an array to store and calculate them. 
 Given that the result allready is an array, as it looks, I might be on the wrong track, maybe.....I -assume- I'll have to use an array for this, if not is there a better way? Cheers 
 Lennartmain(doc,op) { var link = op#ID_USERDATA:1; // A object in a linkfield if(link->IsInstanceOf(Tpointselection) !=FALSE) // If it is a PointSelectionTag run { println("YES"); // It´s a pointselectionTag } else { println("NO"); return; } // Get the selected points , index and position var pointsel = link->GetSelection(); // get whats stored in the Tag var count = link->GetObject()->GetPointCount(); // get the amount of points in the object var i=0; var found=0; for (i=0; i< count; i++) { if(pointsel->IsSelected(i)) { found++; println(link->GetObject()->GetPoint(i)); // Prints the selected points position(s) as an array println(i); // print the indexes of the points println(found); // prints the amount of selected points /* Here I need to add all selected points positions and divide by found to get the avarage position */ } } }
- 
 THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED On 22/06/2006 at 09:03, xxxxxxxx wrote: not sure why you want an array for this, but simply use a vector for this. Just before your for loop set var p = 0; and in your loop p += op->GetPoint(i); then right after your loop, simply divide the sum by your variable "found". p /= found; that´s it. Or did you want to do anything else? Samir 
- 
 THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED On 22/06/2006 at 15:51, xxxxxxxx wrote: No, this is very much what I'm after, thanks! 
 I just have to init the positions as vectors as well and it should be fine:)Cheers 
 Lennart