Angle in collision between a point (or circle) and an 'irregular' curve

Hi guys!

I’m building a custom physics engine to accompany a level-editor. This image shows how the level-editor outputs levels:

Now, some explanation is in order. The curve is defined by the red points. After they are connected in threes by circles (yellow lines show these circles), a system connects them in a ‘streamlined’ way - as shown by the blue lines. This makes the curves flow seamlessly.

Now, these curves are ‘irregular,’ so to say. The pixels’ positions for the curves connecting two points are calculated as following:

You first take 100% of the top curve, 0% from the bottom curve - that’s the first pixel. For the second one, you take 99% of the top curve, 1% from the bottom one. And you go one like that. For example if the top curve’s second pixel’s y-coordinate is 100, and the bottom’s is 0, the second curve would have y-coordinate 99.

Keep in mind that pixels’ coordinates are integers, so getting lines from adjacent pixels doesn’t seem to me like an optimal solution.

For the accompanying physics engine - how do I detect the angle made between a pixel on the curve and a colliding circle (per-pixel collision check)?

I already have a solution in mind, but as I’m not sure so much about it, I’d like to receive some feedback/answers.

Thanks in advance!

I would probably just check a couple pixels to the left or right to get some sort of angle.

1 Like

Thanks @bgilb, that’s what I had to do at the end… had to rework most of the engine, but works flawlessly!

@memonick @bgilb sorry for using this thread to ask you a question? I am new at using Jmonkey so i have a problem. When i load two models, one hand of a model goes into the other. What and how can i do to avoid this collision? Like when i load it for the first time i want if the models are colliding they should move a little to the side where they are not colliding.

Thanks in advance @memonick @bgilb