Issue with simple 2D vector addition

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

Issue with simple 2D vector addition

amundsen
Hello,

I have a vector containing 2D vectors (points), such as:

my_points[[0,0],[0,1],[1,1], [1,0]];

Now I want to move all the points by addition of a vector.

I have tried this:

for (i = [0:len(my_points)]) {
        my_points[i] += [-133.7/2, 0];
}

However, the line "my_points[i] += [-133.7/2, 0];" triggers a syntax error
message. What's wrong?



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Issue with simple 2D vector addition

nophead
Variables in OpenSCAD are immutable, so really named constants. So there are no += or -= operators, hence the syntax error.

you could do:

moved_points = [for(p = my_points) p + [-133.7/2, 0] ];

On Fri, 26 Jun 2020 at 10:25, amundsen <[hidden email]> wrote:
Hello,

I have a vector containing 2D vectors (points), such as:

my_points[[0,0],[0,1],[1,1], [1,0]];

Now I want to move all the points by addition of a vector.

I have tried this:

for (i = [0:len(my_points)]) {
        my_points[i] += [-133.7/2, 0];
}

However, the line "my_points[i] += [-133.7/2, 0];" triggers a syntax error
message. What's wrong?



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Issue with simple 2D vector addition

amundsen
Can't I modify the points in place?



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Issue with simple 2D vector addition

amundsen
In reply to this post by amundsen
Ok, this code still triggers an error message:

pqr = [[0,1],[1,1],[1,0],[0,0]];
px = [for(p = pqr]) p + [-133.7/2, 0]];

The error pointer is inserted on the "r" of "for". I really have no clue
about what is wrong now.



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Issue with simple 2D vector addition

Tim V. Shaporev
Mismatched brackets?

On 6/26/2020 12:54 PM, amundsen wrote:

> Ok, this code still triggers an error message:
>
> pqr = [[0,1],[1,1],[1,0],[0,0]];
> px = [for(p = pqr]) p + [-133.7/2, 0]];
>
> The error pointer is inserted on the "r" of "for". I really have no clue
> about what is wrong now.
>
>
>
> --
> Sent from: http://forum.openscad.org/
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
> .
>


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Issue with simple 2D vector addition

MichaelAtOz
Administrator
In reply to this post by amundsen

> px = [for(p = pqr]) p + [-133.7/2, 0]];

 

                   ^-- delete ']'

 

 

> -----Original Message-----

> From: Discuss [mailto:[hidden email]] On Behalf Of amundsen

> Sent: Fri, 26 Jun 2020 19:55

> To: [hidden email]

> Subject: Re: [OpenSCAD] Issue with simple 2D vector addition

>

> Ok, this code still triggers an error message:

>

> pqr = [[0,1],[1,1],[1,0],[0,0]];

> px = [for(p = pqr]) p + [-133.7/2, 0]];

>

> The error pointer is inserted on the "r" of "for". I really have no clue

> about what is wrong now.

>

>

>

> --

> Sent from: http://forum.openscad.org/

>

> _______________________________________________

> OpenSCAD mailing list

> [hidden email]

> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


Virus-free. www.avg.com

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
OpenSCAD Admin - email* me if you need anything, or if I've done something stupid...
* on the Forum, click on my MichaelAtOz label, there is a link to email me.

Unless specifically shown otherwise above, my contribution is in the Public Domain;
to the extent possible under law, I have waived all copyright and related or neighbouring rights to this work.
Obviously inclusion of works of previous authors is not included in the above.
Reply | Threaded
Open this post in threaded view
|

Re: Issue with simple 2D vector addition

amundsen
Argh!

Thank you.



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org