Question

I'm working on an autonomous rover that navigates partially by ultrasound proximity sensors. Before we implement the hardware we want to do some testing of our algorithms with a simulator, which I am now writing.

One task that I'm having some trouble with is that the ultrasound sensor has a 60 degree field of view. If an object is detected, any point along that 60 degree arc at that radius may have an object, but all points below that radius are guaranteed not to have an object.

What I need to do is write a function that is given an (x,y) coordinate and a bearing (I'm restricting this to the 4 cardinals for now) and have it return to me a list of pixels within a radius and a list of pixels at that radius. With repeated scans from multiple locations and bearings all objects can be found.

My initial thought was to work iterative-ly. Start at the row in front of the sensor and sweep back and forth in progressively wider scans (1,1,3,3,5,5,7,7,etc). However eventually the radii stop aligning with the rows. My new search path would be to figure out how to draw an arc with pixels, then step the radius up to the first collision.

This question asks a similar question, but is only interested in specific points so I believe it is a fundamentally different problem.

how to calculate all points(longitude,latitude) within a given radius from given point (longitude,latitude)?

Was it helpful?

Solution

You can use any Floodfill method to get all integer points in the sector. Precalculate starting and ending angles as

S_Angle = Center_Bearing - Pi/6
E_Angle = Center_Bearing + Pi/6

Important values:

S_Cos = Cos(S_Angle)
S_Sin = Sin(S_Angle)
E_Cos = Cos(E_Angle)
E_Sin = Sin(E_Angle)

Border conditions for sector floodfill:

(x-x0)*S_Sin-(y-y0)*S_Cos >= 0  //point is left to starting ray
(x-x0)*E_Sin-(y-y0)*E_Cos <= 0  //point is right to ending ray
(x-x0)^2+(y-y0)^2 <= R^2        //point is in the range

(probably you may need to exchange >= and <= in the first inequalities pair)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top