# Issue with simple 2D vector addition

7 messages
Open this post in threaded view
|

## Issue with simple 2D vector addition

 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
Open this post in threaded view
|

## Re: Issue with simple 2D vector addition

 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
Open this post in threaded view
|

## Re: Issue with simple 2D vector addition

Open this post in threaded view
|

## Re: Issue with simple 2D vector addition

 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
Open this post in threaded view
|

## Re: Issue with simple 2D vector addition

 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
Open this post in threaded view
|

## Re: Issue with simple 2D vector addition

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

>

>

> 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.

>

>

>

> --

>

> _______________________________________________

 Virus-free. www.avg.com

_______________________________________________
[hidden email]