Advertisement

Trouble getting normals of line segments in 2D

Started by March 24, 2020 01:21 AM
4 comments, last by taby 4 years, 7 months ago

I'm having trouble getting normals (red) from line segments (blue). So far I have all of the normals, but half of them are pointing in the opposite direction.

The code to get the normal is at: https://github.com/sjhalayka/ms_curvature/blob/c3ddbd5d9a995a7241b915c9570248fe331362c1/main.h#L281

The code to draw the normal is at: https://github.com/sjhalayka/ms_curvature/blob/c3ddbd5d9a995a7241b915c9570248fe331362c1/main.h#L123

Thanks for any ideas.

You need to code it further adding more logic to it. Normals will always be uncertain.

If you want all of the normals to point inside the circle, add more logic for it.

A lazy but working idea -

Pick up any line. One only.
Find the “d” for the center of the circle and the line you chosen.

Inside a loop -
Find the normals(perpendiculars? do you need the normals to originate from the centers of the lines?) for all of the lines.
Get the “d” for each line and the end of its own normal.
Compare it to the “d” of the center of the circle.
If sign is equal do nothing. If sign is not equal, mirror the normal. It will point now toward the center.



Basically, you make sure the center and the tip of the normal lie on the same side of each line.

Formula for “d” - https://math.stackexchange.com/questions/274712/calculate-on-which-side-of-a-straight-line-is-a-given-point-located

Advertisement

Do you always follow the clockwise direction for every of the lines? Try this first, before trying my lazy idea.

I checked it now. This here says there is a winding in perpendiculars -

https://gamedev.stackexchange.com/questions/70075/how-can-i-find-the-perpendicular-to-a-2d-vector

So maybe i am wrong to claim the perpendiculars will be uncertain…

I figured it all out. Thanks for your ideas!

This topic is closed to new replies.

Advertisement