discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Issue with simple 2D vector addition

A
amundsen
Fri, Jun 26, 2020 9:24 AM

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/

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/
NH
nop head
Fri, Jun 26, 2020 9:38 AM

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 roald.baudoux@brutele.be 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
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

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 <roald.baudoux@brutele.be> 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 > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
A
amundsen
Fri, Jun 26, 2020 9:44 AM

Can't I modify the points in place?

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

Can't I modify the points in place? -- Sent from: http://forum.openscad.org/
A
amundsen
Fri, Jun 26, 2020 9:54 AM

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/

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/
TV
Tim V. Shaporev
Fri, Jun 26, 2020 9:57 AM

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
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
.

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 > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org > . >
O
OzAtMichael
Fri, Jun 26, 2020 10:15 AM

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

               ^-- delete ']'

-----Original Message-----

From: Discuss [mailto:discuss-bounces@lists.openscad.org] On Behalf Of amundsen

Sent: Fri, 26 Jun 2020 19:55

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.

--


OpenSCAD mailing list

--
This email has been checked for viruses by AVG.
https://www.avg.com

> px = [for(p = pqr]) p + [-133.7/2, 0]]; ^-- delete ']' > -----Original Message----- > From: Discuss [mailto:discuss-bounces@lists.openscad.org] On Behalf Of amundsen > Sent: Fri, 26 Jun 2020 19:55 > To: discuss@lists.openscad.org > 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 > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org -- This email has been checked for viruses by AVG. https://www.avg.com
A
amundsen
Fri, Jun 26, 2020 10:51 AM

Argh!

Thank you.

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

Argh! Thank you. -- Sent from: http://forum.openscad.org/