Calculating a new list from two lists?
Is it posible to combine two lists with a calculation? For example:
List A:
1, 2, 3
List B:
3, 2, 1
List C (output of the node I need):
4, 4, 4
Ist this possible? Which node do I need?
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by cubehexagonal on 24 Oct, 2021 09:49 PM
I want to add two lists of XY coordinates.
First X from list A is added with first X from list B.
First Y from list A is added ith first Y from list B.
etc.
Support Staff 2 Posted by john on 24 Oct, 2021 09:54 PM
Yes, this is easy.
Simply combine the two lists with an ADD node.
See screenshot. List A contains 1, 2, 3. List B contains 3, 2, 1. I simply feed them into an add node and the output is 4, 4, 4.
(I added an integer node because the list and add nodes output floating point numbers which show as n.0. The integer node turns them into integers (which may or may not be necessary).
There is a subtlety to how this works. The add node is configured to take items from a list one at a time. Each time an item from list A and an item from list B arrive at the node it outputs the sum of these two items.
So in this case the node fires 3 times. The first time it outputs 1 + 3 = 4. The second time it outputs 2 + 2 = 4. The third time it outputs 3 + 1 = 4. The result is a list containing three 4s.
Please let me know if you have any other questions. Happy NodeBoxing!
John
3 Posted by cubehexagonal on 24 Oct, 2021 10:03 PM
Thanks!
Sorry, I found out it works with the add node two minutes before seeing your answer. ^^'
Maybe it didn't worked well at first because I didn't split the list into X and Y.
Support Staff 4 Posted by john on 24 Oct, 2021 10:06 PM
Your followup question arrived just as I posted my answer. But I think my answer also works for your followup.
You can separate the Xs and Ys from each list of points using a lookup node, then use the Add node to combine the Xs from A and B and the Ys from A and B. Then turn these two lists back into points by simply feeding the two lists into a point node.
If this is unclear let me know and I will make an example file for you.
John