Valent Posted December 14, 2018 Share Posted December 14, 2018 Hi, I have several meshes and a point and I would like to find primitives/points, the normals of which are directed to that point. To make it so I want to get vectors (and store them as an attribute) from that point to each of the points of these meshes and then compare them to its normals. But the first part doesn't work as I expected, what am I doing wrong? Or should it be done in a different way? facing_to_q.hipnc Quote Link to comment Share on other sites More sharing options...
Jesper Rahlff Posted December 14, 2018 Share Posted December 14, 2018 (edited) all you need to do to create a vector that goes from each point to your target point is the following: vector p0 = point(1,"P",0); vector myvector = p0 - v@P; to calculate the degrees between the two vectors you can use this formula angle = arccosine((vector1*vector2)/(length of vector1*length of vector2)) and this will yield the angle in radians which you then can convert to degrees. you can read more about that here: https://www.wikihow.com/Find-the-Angle-Between-Two-Vectors in vex that looks like this in a point wrangle: //normalize normal vector to make sure the vector length is 1 v@N = normalize(v@N); // get the length of myvector float length = length(myvector); // get the dot product between the two vectors float dotproduct = dot(myvector,v@N); //get the angle between in radians. Note that we do not have to multiply length of my vector with the length of v@N because we know that v@N = 1; f@angle = acos(dotproduct/length); //convert from radians to degrees. f@angle = degrees(f@angle); Lastly you can isolate whichever points you want based on a threshold of f@angle Edited December 14, 2018 by Jesper Rahlff 1 Quote Link to comment Share on other sites More sharing options...
Noobini Posted December 14, 2018 Share Posted December 14, 2018 can also do this, just move the target around to see effect vu_facing.hipnc 1 Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted December 14, 2018 Share Posted December 14, 2018 Just compare both directions using the dot product: vector target = point(1, 'P', 0); vector dir = normalize(target - v@P); f@angle = dot(dir, v@N); target refers to the position of point 0 of the second input. dir contains the direction from each point of the mesh towards the target. angle compares the target direction with the surface normals, ranging from 1 (facing towards) to -1 (facing away). You can switch the wrangle to either points or primitives. facing.hipnc 1 Quote Link to comment Share on other sites More sharing options...
Valent Posted December 14, 2018 Author Share Posted December 14, 2018 Thanks, guys! I tried to re-work it to be able to run on 'detail' and for some reason it doesn't work. Could you please explain why the left_one(in the file attached) doesn't work (they should work the same am I wrong)? facing_q2.hipnc Quote Link to comment Share on other sites More sharing options...
konstantin magnus Posted December 17, 2018 Share Posted December 17, 2018 (edited) It works if you are more explicit about whats a vector and whats a float: eg. v@target instead of just @target. v@a=normalize(v@target-v@P); f@angle=dot(v@N, v@a); v@Cd=vector(f@angle); Also it does not make sense to put vector pt into the for loop, when there is nothing to change. vector pt = point(1, "P", 0); for( int i = 0; i < npoints(0); i++){ setpointattrib(0, "target", i, pt, "set"); } May I ask why you want to put this into a detailwrangle with a for loop after all? The thought behind a point wrangle is already that its running over all points. Edited December 17, 2018 by konstantin magnus 1 Quote Link to comment Share on other sites More sharing options...
Valent Posted December 18, 2018 Author Share Posted December 18, 2018 @konstantin magnus Thanks! On 12/17/2018 at 10:20 AM, konstantin magnus said: It works if you are more explicit about whats a vector and whats a float: eg. v@target instead of just @target. I thought that I have to declare the type of the attribute only once when I initialize it and after that I can access it by @name On 12/17/2018 at 10:20 AM, konstantin magnus said: May I ask why you want to put this into a detailwrangle with a for loop after all? The thought behind a point wrangle is already that its running over all points. For no reason. I just thought that they should work in the same way, so when I got different results I was puzzled. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.