I figured it be helpful to explain how to determine the angle of two edges, I’ll go over the math for it then show a code example in max.
The first step is to get the two positions of the points that make up your edge. We need this to determine the vector of the edge. The image below shows where each point is, the angle we are trying to determine and the vectors we will determine.
The first step is to determine Vector_A. To determine Vector_A you normalize the result of Position_B – Position_A. The second step is determine Vector_B, this is determined by normalizing the result of Position_C – Position_A.
Now that we have our two vectors, we need to get the dot product of Vector_A and Vector_B. Once we have that, we determine the angle by getting the arc cosign of our dot product. The result of that will be the angle that your two vectors/edges create.
Now for the maxscript:
-- Get the vert position
central_vert_pos = polyOp.getVert
-- Determine if this is a junction vert
edge_list = polyOp.getEdgesUsingVert
if (edge_list.numberSet == 2) then (
edge_verts = #{}
-- Get all the non-central edge verts
for current_edge in edge_list do (
central_vert_list = polyOp.getVertsUsingEdge
central_vert_list = central_vert_list - #{
edge_verts += central_vert_list
)
edge_verts_array = (edge_verts as array)
-- Get the vert positions
vert_b_pos = polyOp.getVert
vert_c_pos = polyOp.getVert
-- Get the edge vectors
edge_a_vector = normalize (vert_b_pos - central_vert_pos)
edge_b_vector = normalize (vert_c_pos - central_vert_pos)
-- Get the dot product of the two edges
edge_dot = dot edge_a_vector edge_b_vector
-- Get the arc cos of the dot
edge_angle = acos edge_dot
)
No comments:
Post a Comment