Skip to content
Prev 279669 / 398503 Next

How to scale arrows to approximately fill a plot region?

On 07.12.2011 18:52, Michael Friendly wrote:
Michael, you know it. Go and grab a coffee, this is school maths:

If you have a starting point and a direction as well as the plotting 
region, you can simply calculate a (positive ?) scale so that an arrow 
crosses the border. Now do this for all arrows and all borders and take 
the minimal positive value. Should be few lines of code only.

Therefore:

scale <- c(sapply(bbox[,"x"] - origin["x"], function(i) i/vectors[,1]),
            sapply(bbox[,"y"] - origin["y"], function(i) i/vectors[,2]))
scale <- min(scale[scale > 0])


Best wishes,
Uwe