vectorMath, crossProduct, scalarProduct
All  1-2  3-8

Previous
Next
 From:  Michael Gibson
4951.3 In reply to 4951.1 
Hi Brian,

> The difference between Points and Vectors, and their
> display, is confusing to me.
> I'm thinking Points are displayed as the endpoints of
> vectors, from some origin, and vectors are displayed as
> start and end points...

Well, both points and vectors are represented by the same data - a triplet of x,y,z data.

The difference is the way that data is interpreted - for a point the x,y,z is meant to indicate a specific location in space.

For a vector the x,y,z is meant to represent a direction rather than a position.

Search for something like "vector algebra" to see examples, like:
http://emweb.unl.edu/math/mathweb/vectors/vectors.html

- 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
Next
 From:  Michael Gibson
4951.4 In reply to 4951.1 
Hi Brian,

Your code was:
quote:

function crossProduct( v0, v1, startpt )
{
var vcx = (v0.y * v1.z) - (v0.z * v1.y);
var vcy = (v0.z * v1.x) - (v0.x * v1.z);
var vcz = (v0.x * v1.y) - (v0.y * v1.x);
var vcross_endpt = moi.vectorMath.createPoint( vcx, vcy, vcz );
var vcross = moi.vectorMath.makeVector( startpt, vcross_endpt);
return vcross;
}


So this is a kind of weird way to do cross product - normally the cross product takes in 2 vectors as input and returns one new vector as output which is perpendicular to both inputs, unless they were colinear in which case it will be zero magnitude vector (or almost zero magnitude due to the tiny bit of fuzz in floating point calculations).

The part that you may be getting stuck on is that to build a vector directly from x, y, z values you actually want to use createPoint() to do that, since you will actually hold a point or a vector in the exact same point object since they both just need to contain an x,y,z triplet value. Since both vectors and points have the exact same data in them, there's just one class for them since otherwise they would just have all the exact same properties and methods and everything.

So the return value from crossProduct should be sent back with createPoint() - you only use makeVector for building a vector that represents a displacement between a "from point" and a "to point".

So a more normal cross product function would look like this:

code:
function crossProduct( v0, v1 )
{
    var x = (v0.y * v1.z) - (v0.z * v1.y);
    var y = (v0.z * v1.x) - (v0.x * v1.z);
    var z = (v0.x * v1.y) - (v0.y * v1.x);

    return moi.vectorMath.createPoint( x, y, z );
}



And normally the result of a scalar product/dot product does not produce a vector as output, but instead generates a single number as the output. It's not the same thing as "scaling" a vector.

So normally the dot product would be like this:
code:
function dotProduct( v0, v1 )
{
    return (v0.x * v1.x) + (v0.y * v1.y) + (v0.z * v1.z);
}


If you want to scale up a vector to increase or decrease its magnitude you would do something like this:

code:
function scaleVector( v, factor )
{
    var x = v.x * factor;
    var y = v.y * factor;
    var z = v.z * factor;
    return moi.vectorMath.createPoint( x, y, z );
}



That one produces a new scaled vector as output from the function.

There is also a method .scale( ) that you can call on a point or vector to modify that vector by a scale factor.

To do that you would do something like this:

var vector = <get a vector somewhere...>
vector.scale( 5.0 );

That .scale method is on IMoiPoint - look up IMoiPoint in the moi.idl file to see what else is there - that's also where you will see the properties for x, y, z listed.

There's not a whole lot of stuff set up for scripting this stuff yet - in the future I want to expand the library of functions available to script for doing this kind of stuff. Right now you will need to make some various helper functions of your own though.

Hope this helps!

- Michael

EDITED: 21 Feb 2012 by MICHAEL GIBSON

  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:  bemfarmer
4951.5 
Thank you very much Michael. Your information is a big help.

(The reference book placed such an emphasis on Points and vectors being different...)


I should have said "scaling a vector" by multiplying it by a number, not scalar product...

I need to have a look at the Moi idl file. I think windows is hiding it...

One script coming up, in a week or a month, or ... :-)

Edit: (I meant the David Morrill documentation.)
  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
4951.6 In reply to 4951.5 
> (The reference book placed such an emphasis on
> Points and vectors being different...)

It's not necessarily bad to think of them as being different in how they are used, but since they contain the same data pretty often there is just one actual class to represent both of them.

- 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
Next
 From:  bemfarmer
4951.7 In reply to 4951.4 
Thank you again Michael. .scale method looks very concise.

(My script was making tiny microcurves... )
  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:  Frenchy Pilou (PILOU)
4951.8 In reply to 4951.7 
< microcurves
no problem a long you don't make micro "black holes" ;)
---
Pilou
Is beautiful that please without concept!
My Gallery
  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

 

 
 
Show messages: All  1-2  3-8