Translating points and finding correct normal vector

2 Ansichten (letzte 30 Tage)
Matteo Sangermani
Matteo Sangermani am 14 Feb. 2019
Beantwortet: Joel Handy am 14 Feb. 2019
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 of inward of a specific distance (see Example Figure: Red: outer perimeter, Green: inner perimeter; Blue: normal vector of outer perimeter’s points). Briefly, in order to do that I 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 a point 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) gives me angles between 0 and 180 degree. It works, although it is not an elegant solution. However, the big problem is that if first normal vector found points outward, all remaining points are translated outward.
Perhaps, if I could get angle values from 0 to 360, I could solve the problem and understand the orientation of my segment (A-to-B versus B-to-A; see attached Concept Figure).
Best and thank you in advance,
Matteo

Akzeptierte Antwort

Joel Handy
Joel Handy am 14 Feb. 2019
Sounds like what you really want to do is "shrink" your perimiter. Is that accurate? If so, projecting points back along these normals I don't think will have the desired effect. It will change the shape. It would make more sense to me to project them back along a line splitting the angle formed by the two segments adjacent to the point.
Either way, ou still have the same problem of figuring out which way is "in" and which way is "out". One method would be to use the inpolygon function and guess and check. Pick on direction, use inpolygon to check if you are right, switch if you are not. There are probably better ways to do it. Inpolygon is pretty slow. You'll have to be extra careful with the distance you project your point in case your shape is very thin. You could projected right past the other side and by "outside" even though you picked the right direction.
Lastly, look into using that atan2 function to compute angles between two vectors. That will give you a value between -180 and 180 degress.

Weitere Antworten (0)

Kategorien

Mehr zu Mathematics and Optimization finden Sie in Help Center und File Exchange

Produkte


Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by