Points Translation and finding correct normal direction

1 view (last 30 days)
Dear everyone,
I have the following problem. I start with a perimeter describing as a set of ordered points that define an object. I want to create an “inner” perimeter, by translating each point "inward" of a specific distance (see example figure: Red: outer perimeter; Green: inner perimeter; Blue: normal vectors for outer perieter points). Briefly, in order to do that my code (see attached .m file) take any two adjacent points of the outer perimeter (A and B) and find the normal vector to this segment. The normal vector is then used to translate point A of a specific distance in the direction pointed by the normal vector.
The problem is that there are two possible directions and I have a hard time to ensure to univocally point in the “inward” direction. What I do is to calculate the angle between the normal vector and the x-axis. However, the solution I got (see Code attached), I can get angles between 0 and 180 degree. It works, although it is not an elegant solution. The major problem is that, if the first normal vector I find is pointing outward, all will be translated outward.
What I want is to be able to get values from 0 to 360, in this way I think I can understand the orientation of my segment (A-to-B versus B-to-A; see attached Concept Figure)
Best and thank you in advance,

Answers (1)

Matt J
Matt J on 14 Feb 2019
Compute the vector V from the centroid to each of your points and correct the orientation of the gradient as follows
gradient = -gradient*sign(dot(V,gradient))

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!