Problem
Suppose $\varphi\colon V=\mathbb R^n\to V$ be a differmorphism and $d\varphi$ is its tangent mapping. $\langle\circ,\circ\rangle$ is a nondegenerate (symmetric or symplectic) bilinear form on $V$. If $d\varphi$ preserves the scalar product everywhere, i.e. $\langle u,v\rangle=\langle d\varphi_x(u),d\varphi_x(v)\rangle$ for all $x\in V$ and $u,v\in V$ (identify $T_xV$ with $V$), should $\varphi$ be affine?
Thoughts
Suppose $\langle\circ,\circ\rangle$ is an inner-product, the result seems true, for it's not hard to show that $\varphi$ preserves arc length by curvilinear integral, then if $l_{pq}$ is the segment connecting $p$ and $q$ of the minimal distance, then $\varphi(l_{pq})$ connects $\varphi(p)$ and $\varphi(q)$ of the minimal distance, hence $l_{\varphi(p)\varphi(q)}$.
Backgrounds
The problem arises from the twin paradox in special relativity. The frame of reference of the traveling twin isn't inertial therefore isn't equivalent to the inertial frame of reference on earth, thus the time dilation argument is nonsense. Mathematically, if the coordinate system of the spacetime in which the frame of reference isn't inertial, we cannot determine the proper time of a world line naïvely from integrating $c^{-1}ds=\sqrt{dt^2-c^{-2}(x^2+y^2+z^2)}$ in the new coordinate system, i.e, the arc length of the world line isn't preserved under the coordinate transformation.
Any idea? Thanks!
Edit
The symplectic case is already disproved by Seub.
Yes, $\varphi$ should be affine.
1st proof: assume $\varphi$ is $C^2$ and define $T_{ijk}=\langle \partial_i\partial_j\varphi, \partial_k\varphi\rangle$ (I use $\partial_i$ for ${\partial\over \partial x_i}$). Then $T_{ijk}$ is symmetric in $ij$ and anti-symmetric in $jk$ (apply $\partial_i$ to $\langle\partial_j\varphi, \partial_k\varphi\rangle=\langle\partial_j, \partial_k\rangle$).
It follows that $T_{ijk}=0$ (proof: $T_{ijk}=-T_{ikj}=-T_{kij}=\ldots=-T_{ijk}$).
Hence $\partial_i\partial_j\varphi=0$ (this is where we use that the inner product is non degenerate), so $\partial_j\varphi$ is constant and $\varphi$ is affine.
Note that we only used the fact that the inner product is non-degenerate, but not necessarily positive definite. Also, this argument works even if $\varphi$ is defined only locally (ie in some open subset of $V$). However we need $\varphi$ to be $C^2$.
2nd proof (less elementary, but more geometric). We can find an affine isometry, say $A$, such that $\tilde\varphi:=A\circ\varphi$ satisfies $\tilde\varphi(0)=0,$ $d\tilde\varphi_0=id$ (take $A(x)=(d\varphi_0)^{-1}x-\varphi(0)$).
I claim that $\tilde\varphi=id$. Let $x\in V$. Define $\gamma:[0,1]\to V$ by $\gamma(t)=tx.$ Then $\gamma$ is a geodesic. Hence $\tilde\gamma:=\tilde\varphi\circ\gamma$ is also a geodesic (note that $\tilde\varphi$ is an isometry, as a composition of isometries). But $\tilde\gamma(0)=\gamma(0)=0,$ $\dot{\tilde\gamma}(0)=\dot \gamma(0)=x,$ and both satisfy the same 2nd order ODE, hence $\tilde\gamma=\gamma.$ In particular, $x=\gamma(1)=\tilde\gamma(1)=\tilde\varphi(x)$.
Hence $\tilde\varphi=id,$ thus $\varphi=A^{-1}$ and is affine.