To extract coordinates of a point to assign them to another point
where the z is negative…thanks for your help.
example
pt1 = [50, 65, 0]
pt1a = [pt1.x + 5, pt1.y + 5, pt1.z - 5]
…“pt1.z - 5”…incorrect ???
result I would like to achieve = pt1a = [55, 70, -5]…
Just to be clear, the original problem was that ’ -5’ (with a space before ‘-’ but no space between ‘-’ and ‘5’) is taken as a negative literal number not a subtraction operator combining two terms, so the expression ‘pt1.z -5’ is a syntax error. The various ways of adding or removing spaces around ‘-’ alter the interpretation of the expression, making clear that you intended a subtraction.
Edit: I hesitate to contradict @TIG, but this has nothing to do with the code editor.
You’re probably correct - since I’ve never used the code-editor I can’t be sure.
It’s always best to use consistent spaces or none, and of course parentheses can help too…
if pt1 = [50, 65, 0] integer in inches.
pt1a = [(pt1.x + 5), (pt1.y + 5), (pt1.z - 5)] if the syntax is right…
result is [55, 70, -5]
or if instead of inches I use the cm, being in Italy…
if pt1 = [50.cm, 65.cm, 0.cm] if the syntax is right. integer…
pt1a = [(pt1.x + 5.cm), (pt1.y + 5.cm), (pt1.z - 5.cm)] if the syntax is right…
result is [55, 70, -5] units of measurement in cm since I used .cm in pt1…
or even…
if pt1 = [50,0.cm, 65,0.cm, 0,0.cm] decimal number in cm… is it right to use the comma? 50,0.cm or you have to use the 50.0.cm
pt1a = [(pt1.x + 5,0.cm), (pt1.y + 5,0.cm), (pt1.z - 5,0.cm)] if the syntax is right…
result is [55,0, 70,0, -5,0]
Your ‘if’ syntax is wrong.
Also in Ruby the decimal separator is always .
Unlike your locale where it will probably be a ,
Ruby’s list separator is always a ,
Again unlike your locale where it will probably be a ;
So something like this will probably work…
if pt1 == [50.cm, 65.cm, 0.cm] ### note the double ==, to test equality
pt1a = [(pt1.x + 5.cm), (pt1.y + 5.cm), (pt1.z - 5.cm)] ### note the single =, to set the reference
else
pt1a = pt1.clone ### ? fallback result ?
end