1

Hopefully the thread title isn't confusing - I'm trying to find out how would it be possible to make a different way of proximity warning with GPS.

Default/simplest way is by forming a radius around a goal waypoint, so the proximity criteria will get triggered when you're "inside" the circle. I know about geofencing but that does seem very demanding and complex, so I'd like to ask if something like shown in this pic would be achievable.

So instead of proximity criteria being a radius around a waypoint, forming a circular geofence so to speak, would it be possible to create a half-circle like this, at a specific angle.

enter image description here

Varonne
  • 89
  • 5
  • What are you trying to accomplish? I mean, I understand your question, but I'm curious as to why, simply because GPS isn't really all that accurate (however, I don't know how big your semicircle is). – Steve Nov 20 '22 at 22:13
  • 1
    Also, this isn't really an Arduino question, it's a geometry question. – Steve Nov 20 '22 at 22:14

1 Answers1

2

Let

  • (x, y) be the Cartesian coordinates of the vector going from the waypoint to your position

  • radius be the radius of the circle

  • theta be the orientation of the straight line, in radians.

You can then build a unit vector normal to the straight line:

n = (cos(θ+π/2), sin(θ+π/2)) = (−sin θ, cos θ)

You are on the colored side of the line if the scalar product of n with (x, y) is positive.

In code:

bool is_inside(float x, float y)
{
    float product = - x * sin(theta) + y * cos(theta);
    float r2 = x * x + y * y;
    return r2 <= radius * radius && product >= 0;
}
Edgar Bonet
  • 43,033
  • 4
  • 38
  • 76
  • Thank you so much for showing the way! But one thing crossed my mind, as I'm moving the "half circle geofence" should remain within the same angle, not relative to me but to some constant, I'm thinking "north"...which means this gets more complex and closer to actual vehicle navigation? Because one thing to make this work correctly as well, is to have the target destination have a reference "north" so that the geofence always faces the proper direction. Which makes me think, is it possible to assign such constant, and make this half geofence face in a destined compass derived direction? – Varonne Nov 20 '22 at 14:51
  • @Varonne: If you want theta to be a constant, just keep it constant. There is no reason it should be more complex than this. – Edgar Bonet Nov 20 '22 at 15:13