Let $H$ be a Hilbert space and let $g \in H$ be a fixed nonzero element. Consider the maximization problem $$\max \left\{ (f,g): f \in H \quad \text{and} \quad \|f\|\leq 1 \right\}$$
This maximum is equal to $\|g\|$ and a maximizer function is $f_0 = g/\|g\|$. Suppose now $K \subset H$ is convex and closed. Consider the above maximization problem, but restricted to $K$
$$\max \left\{ (f,g): f \in K \quad \text{and} \quad \|f\|\leq 1 \right\} \tag{1}$$
My question is, what is the above maximum value and can we describe a maximizer using the projection operator $P:H \to K$? If not, under what general assumptions (on $K$ and $g$) can we do this?
In special cases this is possible. For example suppose $K$ is a cone (or a subspace), then $g$ satisfies the condition
$$(g-Pg,Pg) = 0 \tag{2}$$
Now by the characterization of the projection $(g-Pg,k-Pg) \leq 0$ for any $k \in K$. Applying this to $k=f$ and using (2) gives $(g-Pg,f) \leq 0$, hence
$$(f,g) = (f,Pg) + (f, g-Pg) \leq (f,Pg)$$
So assuming in addition that $K$ is a cone, the maximum in (1) is bounded by $\|Pg\|$ and this value is in fact attained and the maximizer is $f_1 = Pg/\|Pg\|$.
More generally, what can be said when $K$ is just a closed and convex set? Any insight or references will be much appreciated!