Script question about Points, Objects, vectorMath...

Next
 From:  bemfarmer
5194.1 
Hi Michael,
I am using a for loop with var mypoint = moi.vectorMath.createPoint( x,y,z ); to create 3D points, (which are apparently vectors), and want to save the points in either an array (of arrays?), or perhaps an object list, in order to do additional vector mathematical operations on the x, y, and z coordinates, which will move the points, before sending them to a point or line factory.
What is the best way to save the N points?

Can multiple values for mypoint be saved in an array, or should the pointfactory.calculate() be done, which seems like additional overhead?
Can the points be stored in an object list?

It is very confusing…seems like there are 4 ways to do it...

Thank you.
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
Next
 From:  Michael Gibson
5194.2 In reply to 5194.1 
Hi Brian yes you're talking about 2 different kinds of "points" there.

One that you are creating by moi.vectorMath.createPoint() is a "data structure point" - it's a low level object that contains only an x,y,z value.

That kind of point is not a geometry database object that can go in an object list - object lists are built to contain geometry database objects, which have all kinds of various properties on them like styles, hidden states, object names, etc... The "point object" that you create by a pointfactory.calculate() is a geometry database object and can be put in an object list, it also contains x,y,z values but also in addition to that has all that other stuff for styles, object names, selection/hidden/locked states, etc... as well.

If you want to build an array you can use a Javascript array to do that, you don't necessarily need to use a MoI-specific object list which is a more specialized container that is only focused on holding geometry database objects.

You can get some tips on using general purpose Javascript arrays here:
http://www.w3schools.com/js/js_obj_array.asp

The generic Javascript array can hold anything in it, not only just geometry database objects like the more specialized MoI object list container.


The most basic usage is to do something like:

// Create an array.
var my_point_array = new Array();

// Add things to it.
my_point_array.push( pt1 );
my_point_array.push( pt2 );
my_point_array.push( pt3 );


// Traverse the array
for ( var i = 0; i < my_point_array.length; ++i )
{
    var pt = my_point_array[i];
    ... do something with this point...
}

> to create 3D points, (which are apparently vectors),

Both points and vectors are made up of x,y,z coordinate triplets, so in practical use they can be represented with the same objects. It's just a matter of what you use the x,y,z data to do.


- Michael
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged

Previous
 From:  bemfarmer
5194.3 In reply to 5194.2 
Thank you very much Michael.

Exactly what I needed.
Your explainations make the matter much easier to understand.
Back to working on the script...

Sincerely,
- Brian
  Reply Reply More Options
Post Options
Reply as PM Reply as PM
Print Print
Mark as unread Mark as unread
Relationship Relationship
IP Logged
 

Reply to All Reply to All