### @P vs Point() problem

665   6   1
Member
4 posts
Joined: Feb. 2017
Offline
I'm trying to transform some points in a point wrangle and

vector vec = set(1,1,1);
@P += vec;
@P -= vec;

returns points to their starting position as expected, but

vector vec = set(1,1,1);
@P = point(0, “P”, @ptnum)+vec;
@P = point(0, “P”, @ptnum)-vec;

gives different results, as if the first transform didn't do anything.
why are the results different? am I using point() wrong? sorry if this is too common a question.
Member
37 posts
Joined: July 2013
Offline
It's down to the way you are setting the @P attribute. By putting a + or - in front of = you are adjusting the value. Without the + or - you are setting the attribute so the first expression will be overwritten by the second.
Member
4 posts
Joined: Feb. 2017
Offline
If that's the case, then why does

vector vec = set(1,1,1);
@P = @P+vec;
@P = @P-vec;

work the same way as the original

vector vec = set(1,1,1);
@P += vec;
@P -= vec;

yet acts different than

vector vec = set(1,1,1);
@P = point(0, “P”, @ptnum)+vec;
@P = point(0, “P”, @ptnum)-vec;

don't @P and point(0, “P”, @ptnum) do the same thing?
Member
37 posts
Joined: July 2013
Offline
They do mean the same thing, if you bound both ways to two new attributes they would match.

I think the reason that the top expressions work is because of the way code is read in general coding practices.
@P = @P+vec is recognised as @P += vec. The point expression being a vex function probably isn't recognised the same way.
Member
3546 posts
Joined: July 2007
Online
you have to imagine it step by step:

```vector vec = set(1,1,1);
// imagine @P is {0,0,0}
@P = @P+vec; // now you are altering @P to be {0,0,0} + {1,1,1} = {1,1,1}
// so from now on @P is no longer {0,0,0} but {1,1,1}
@P = @P-vec; // now you are alreting @P to be {1,1,1} - {1,1,1} so back to {0,0,0}
```

the same goes for @P += and -= example as that's just the shorter syntax to the same assignment
but in here:

```vector vec = set(1,1,1);
// imagine @P is {0,0,0}
@P = point(0, “P”, @ptnum)+vec; // now you are altering @P to be {0,0,0} + {1,1,1} = {1,1,1}
// so from now on @P is no longer {0,0,0} but {1,1,1}
// however point(0, “P”, @ptnum) function takes P attrib from the input 0 so it will always return {0,0,0}
// even after this point as it has no connection to @P
@P = point(0, “P”, @ptnum)-vec; // therefore here you are setting @P to be again {0,0,0} - {1,1,1} so {-1,-1,-1}
```

also worth noting that point(0, “P”, @ptnum) is pretty ambiguous andin this case Houdini makes a good guess you want to use vector representation, but if using within a longer expression and not just on it's own as a part of assignment it's safer to use vector(point(0, “P”, @ptnum))
Tomas Slancik
FX Supervisor
Method Studios, NY
Member
140 posts
Joined: Feb. 2017
Offline
I'm not technical so pls don't hang me for this…but I'll try:

if you use

@P += vec;
@P -= vec;

then you are using the updated pos in the wrangle.

if you use

@P = point(0, “P”, @ptnum)+vec;
@P = point(0, “P”, @ptnum)-vec;

then the point() refers to what you STARTED with before you got into this wrangle.

So use this test:

vector vec = set(1,1,1);
@P += vec;
printf(“y:%f\n”,vector(point(0, “P”, @ptnum)).y);
printf(“Py:%f\n”, @P.y);

and you'll see clearly @P inside the wrangle is updated…but point() is not using the @P inside the wrangle. It's using the orig input before any manipulation.
Edited by vusta - March 8, 2018 20:18:47
Member
4 posts
Joined: Feb. 2017
Offline
Thank you tamte and vusta. I understand now.