vector question

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

vector question

David Goodenough
I know I can add two vectors to produce a longer vector, and I can
multiply or divide all the elements in a vector by a factor, but
how can I add a number to all elements of a vector (presumably
creating a new vector as a result)?

David

Reply | Threaded
Open this post in threaded view
|

Re: vector question

Giles Bathgate-2

I think you would need a componentwise add operator which openscad dosen't have.

Reply | Threaded
Open this post in threaded view
|

Re: vector question

nophead

a = [1,2,3] + [1,1,1];

echo(a);


ECHO: [2, 3, 4]


On 27 June 2012 12:08, Giles Bathgate <[hidden email]> wrote:

I think you would need a componentwise add operator which openscad dosen't have.


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


Reply | Threaded
Open this post in threaded view
|

Re: vector question

David Goodenough
In reply to this post by Giles Bathgate-2
On Wednesday 27 Jun 2012, Giles Bathgate wrote:
> I think you would need a componentwise add operator which openscad dosen't
> have.
OK, another approach, is there a way to access elements of a vector
other than for?  Or can I use for to cycle round creating a new vector?

David

Reply | Threaded
Open this post in threaded view
|

Re: vector question

nophead
You can probably access elements sequentially with a recursive function but I don't know any way to add new elements to a vector or concatenate 2.

On 27 June 2012 12:22, David Goodenough <[hidden email]> wrote:
On Wednesday 27 Jun 2012, Giles Bathgate wrote:
> I think you would need a componentwise add operator which openscad dosen't
> have.
OK, another approach, is there a way to access elements of a vector
other than for?  Or can I use for to cycle round creating a new vector?

David
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad

Reply | Threaded
Open this post in threaded view
|

Re: vector question

nophead
I know I can add two vectors to produce a longer vector 

How do you do that? 

On 27 June 2012 12:34, nop head <[hidden email]> wrote:
You can probably access elements sequentially with a recursive function but I don't know any way to add new elements to a vector or concatenate 2.


On 27 June 2012 12:22, David Goodenough <[hidden email]> wrote:
On Wednesday 27 Jun 2012, Giles Bathgate wrote:
> I think you would need a componentwise add operator which openscad dosen't
> have.
OK, another approach, is there a way to access elements of a vector
other than for?  Or can I use for to cycle round creating a new vector?

David
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad


Reply | Threaded
Open this post in threaded view
|

Re: vector question

David Goodenough
On Wednesday 27 Jun 2012, nop head wrote:
> > I know I can add two vectors to produce a longer vector
>
> How do you do that?
Probably that I misunderstood the vector operators section of the
manual.

There is a difference in the language used to describe the way that
vector +- work compared to */, which lead me to believe that adding
a number to a vector, or adding a vector to vector created a longer
vector, while multiplying two vectors was (to use Giles word)
componentwise.  If they are the same, why not describe them all
together?

David

>
> On 27 June 2012 12:34, nop head <[hidden email]> wrote:
> > You can probably access elements sequentially with a recursive function
> > but I don't know any way to add new elements to a vector or concatenate
> > 2.
> >
> >
> > On 27 June 2012 12:22, David Goodenough
> > <[hidden email]
> >
> > > wrote:
> >> On Wednesday 27 Jun 2012, Giles Bathgate wrote:
> >> > I think you would need a componentwise add operator which openscad
> >>
> >> dosen't
> >>
> >> > have.
> >>
> >> OK, another approach, is there a way to access elements of a vector
> >> other than for?  Or can I use for to cycle round creating a new
vector?
> >>
> >> David
> >> _______________________________________________
> >> OpenSCAD mailing list
> >> [hidden email]
> >> http://rocklinux.net/mailman/listinfo/openscad


Reply | Threaded
Open this post in threaded view
|

Re: vector question

nophead
If there was vector concatenation one could do a lot of things with recursive functions I think. That gets round not having modifiable variables by using a functional style.

For you original problem, adding a constant to all the elements, I suspect it would be very easy to add as it already works for multiply and divide.

If the number of elements is known you can do it by adding a vector made by repeating the constant.

If there is a small range of lengths you could do it with a function with some ternary operators selecting different length vectors to add.

On 27 June 2012 12:48, David Goodenough <[hidden email]> wrote:
On Wednesday 27 Jun 2012, nop head wrote:
> > I know I can add two vectors to produce a longer vector
>
> How do you do that?
Probably that I misunderstood the vector operators section of the
manual.

There is a difference in the language used to describe the way that
vector +- work compared to */, which lead me to believe that adding
a number to a vector, or adding a vector to vector created a longer
vector, while multiplying two vectors was (to use Giles word)
componentwise.  If they are the same, why not describe them all
together?

David
>
> On 27 June 2012 12:34, nop head <[hidden email]> wrote:
> > You can probably access elements sequentially with a recursive function
> > but I don't know any way to add new elements to a vector or concatenate
> > 2.
> >
> >
> > On 27 June 2012 12:22, David Goodenough
> > <[hidden email]
> >
> > > wrote:
> >> On Wednesday 27 Jun 2012, Giles Bathgate wrote:
> >> > I think you would need a componentwise add operator which openscad
> >>
> >> dosen't
> >>
> >> > have.
> >>
> >> OK, another approach, is there a way to access elements of a vector
> >> other than for?  Or can I use for to cycle round creating a new
vector?
> >>
> >> David
> >> _______________________________________________
> >> OpenSCAD mailing list
> >> [hidden email]
> >> http://rocklinux.net/mailman/listinfo/openscad

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad

Reply | Threaded
Open this post in threaded view
|

Re: vector question

Doug Mcnutt
At 13:06 +0100 6/27/12, nop head wrote:
>There is a difference in the language used to describe the way that
>vector +- work compared to */, which lead me to believe that adding
>a number to a vector, or adding a vector to vector created a longer
>vector, while multiplying two vectors was (to use Giles word)
>componentwise.  If they are the same, why not describe them all
>together?


I haven't done vectors with openscad - yet.  But that kind of speech worries me a whole lot. Perl 6 has introduced component by component multiplication like

z1 = x1*y1 ,  z2 = x2*y2 ,  z3 = x3*y3

and the like.  Such ideas are a disaster for folks who think of vectors as a way to represent a point in 3D space or who like to do Hamiltonian mechanics on satellites or to build 3 phase electric power systems.

The initial problem, adding a constant to a vector can be thought of as adding a special vector you create with all three of its components the same and equal to the value you want to add.

Now just add the temporary vector to the old one.

There are two ways to multiply vectors.  The dot product multiplies the components in a component by component fashion and then adds the three products together to get a number, not a vector.  The numeric value is the product of the two vector lengths and the cosine of the angle between them. It's also the length of the projection of one of the vectors on the other.

The cross product does something similar (look up the phunny formulas) to obtain a vector that is perpendicular to both input vectors with length equal to the sine of the product of the two lengths.  If Z = X cross Y and you hold your right hand fingers so they show the rotation of X into Y,   Z points in the direction of your thumb.

One can also multiply a vector by a scalar.  That makes each element of the vector get longer or shorter by a ratio given by the scalar. That's used in the famous F = mA formula where the scalar is the mass and the force and acceleration are vectors.  It's what makes the earth go around.

Now I need to get into openscad and do some testing. I'm going to be very upset if they got it wrong the way perl 6 does. That would be as bad as Excel returning +4 for the formula = -2^2.

--
--> If you are presented a number as a percentage, and you do not clearly understand the numerator and the denominator involved, you are surely being lied to. <--

Reply | Threaded
Open this post in threaded view
|

Re: vector question

clothbot
See https://github.com/openscad/openscad/blob/master/testdata/scad/misc/vector-values.scad for the tested matrix & vector subset of math operators.

It's just dot-product-based multiplication operators.

Andrew.

On 2012-06-30, at 5:34 PM, Doug Mcnutt wrote:

At 13:06 +0100 6/27/12, nop head wrote:
There is a difference in the language used to describe the way that
vector +- work compared to */, which lead me to believe that adding
a number to a vector, or adding a vector to vector created a longer
vector, while multiplying two vectors was (to use Giles word)
componentwise.  If they are the same, why not describe them all
together?


I haven't done vectors with openscad - yet.  But that kind of speech worries me a whole lot. Perl 6 has introduced component by component multiplication like

z1 = x1*y1 ,  z2 = x2*y2 ,  z3 = x3*y3

and the like.  Such ideas are a disaster for folks who think of vectors as a way to represent a point in 3D space or who like to do Hamiltonian mechanics on satellites or to build 3 phase electric power systems.

The initial problem, adding a constant to a vector can be thought of as adding a special vector you create with all three of its components the same and equal to the value you want to add.

Now just add the temporary vector to the old one.

There are two ways to multiply vectors.  The dot product multiplies the components in a component by component fashion and then adds the three products together to get a number, not a vector.  The numeric value is the product of the two vector lengths and the cosine of the angle between them. It's also the length of the projection of one of the vectors on the other.

The cross product does something similar (look up the phunny formulas) to obtain a vector that is perpendicular to both input vectors with length equal to the sine of the product of the two lengths.  If Z = X cross Y and you hold your right hand fingers so they show the rotation of X into Y,   Z points in the direction of your thumb.

One can also multiply a vector by a scalar.  That makes each element of the vector get longer or shorter by a ratio given by the scalar. That's used in the famous F = mA formula where the scalar is the mass and the force and acceleration are vectors.  It's what makes the earth go around.

Now I need to get into openscad and do some testing. I'm going to be very upset if they got it wrong the way perl 6 does. That would be as bad as Excel returning +4 for the formula = -2^2.

--
--> If you are presented a number as a percentage, and you do not clearly understand the numerator and the denominator involved, you are surely being lied to. <--
_______________________________________________
OpenSCAD mailing list
[hidden email]
http://rocklinux.net/mailman/listinfo/openscad
http://openscad.org - https://flattr.com/thing/121566

--

"The future is already here.  It's just not very evenly distributed" -- William Gibson

Me: http://clothbot.com/wiki/