java - Find the length of a vector based on a rule -
i creating vertex array mesh given points.so far able create continuous mesh thickness.however there problem @ intersection of 2 line segments, vectors between segment's sizes needs bigger or smaller depending on situation in order have continuous look.
what have now:
with given angles theta1 , theta2, how can calculate length of red vectors?
what want:
how structured mesh:
you're making more complicated needs be.
let's start calculating red arrows. line segment (p_i, p_j)
, can calculate segment's normal with:
dir = normalize(p_j - p_i) normal = (-dir.y, dir.x) //negate if want other direction
at connection point between 2 segments, can average (and re-normalize) incident normals. gives red arrows.
the question remains how need shift. resulting offset line segment o_l
given offset of vertex o_v
is:
o_l = o_v * dot(normal_l, normal_v)
this means following: both normals unit vectors. hence, dot product @ one. case when both line segments parallel. then, entire offset of vertex transferred line. smaller angle becomes, smaller becomes transferred offset. e.g. if angle between 2 consecutive line segments 120°, dot product of normals 0.5. if shift vertex 1 unit along normal, both line segment have thickness of 0.5.
so, in order produce specific line thickness (o_l
), need shift vertex o_v
:
o_v = o_l / dot(normal_l, normal_v)
the construction averaging line segments' normal vertex normal ensures dot(normal_l1, normal_ v) = dot(normal_l2, normal_v)
, i.e. resulting line thickness equal both lines in case.
Comments
Post a Comment