Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Getting Midpoint using array(?)

    Scheduled Pinned Locked Moved SDK Help
    3 Posts 0 Posters 308 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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
      Lennart

      main(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  
      */  
      }  
      }  
        
      }
      
      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        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

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          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

          1 Reply Last reply Reply Quote 0
          • First post
            Last post