I am writing a music display program and need to draw a \'slur\' between two notes. A slur is a curved line linking two notes - just to be clear.
I took legends2k excellent answer and converted to Java on Android. This might help someone save some time.
private PointF getPerpendicularPoint(int startX, int startY, int stopX, int stopY, float distance)
{
PointF M = new PointF((startX + stopX) / 2, (startY + stopY) / 2);
PointF p = new PointF(startX - stopX, startY - stopY);
PointF n = new PointF(-p.y, p.x);
int norm_length = (int) Math.sqrt((n.x * n.x) + (n.y * n.y));
n.x /= norm_length;
n.y /= norm_length;
return new PointF(M.x + (distance * n.x), M.y + (distance * n.y));
}