Jump to content

how to find faces/points which are facing to another point


Valent

Recommended Posts

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

Link to comment
Share on other sites

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 by Jesper Rahlff
  • Like 1
Link to comment
Share on other sites

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);
  1. target refers to the position of point 0 of the second input.
  2. dir contains the direction from each point of the mesh towards the target.
  3. 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

  • Like 1
Link to comment
Share on other sites

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 by konstantin magnus
  • Like 1
Link to comment
Share on other sites

@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. 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...