Hi,

I'm trying to create an agent vehicle which drives along a path of a uniform width, and finds the distance to the edge of the path directly ahead of it. Like this:

The aim is to somewhat simulate how far the agent can see down the road.

Since the thickness of a plot curve is unrelated to the units of the axis, and has no means of interacting with objects this would be no use.

I also considered shadebetween function, however this only can shade between the y values of 2 functions, so for a vertical curve it cannot produce any width to the path.

I then realised using parametric equations of form (x(t), y(t)) would likely make most sense and wrote some code which roughly gets the boundarys at a fixed distance from the centre path equation, by adding the x-y components of the reciprocal of the gradient:

For certain simple path equations such as this one, it roughly works other than the areas between which the boundary curves overlap themselves (I would need to find these points of intersection and break the curves up to remove these squigly inner bits). Any advice on this would be much appreciated cause this seems like it will be tricky, if not computationally heavy.

More annoyingly, due to the nature of the trig functions involved, for more complex graphs which include a vertical turning point, the left and right boundaries seem to swap over:

and

Clearly this is not the behaviour I had in mind.. and I'm not sure what I can do to fix it, I think maybe using piecewise trig may be a potential solution to avoid the jumping from + to -, though I'm not sure where I would put these breakpoints (I've tried just using abs(arctan(...)) with no luck).

If anyone could help wih this that would be really appreciated, or even suggest a better approach to this problem!

Thanks

[code] agentpath.mw