# Drawing a parametric line with unitary director vector produces a longer straight line using PGFPlots

I would like to plot a normal bounded line to a surface in a point.

The surface is y=x and the point is (1/2,1/2,1). The gradient is (-1,1,0), and at point (1/2,1/2,1) is still the same, thus the normal line would be (x-1/2)/(-1)=(y-1/2)/(1)=(z-1)/(0), hence the line is described by (.5,.5,1)+t(-1,1,0).

However, I want the line to be bounded, in order to make a unitary director vector, but I am not able to do these. I am using t between 0 and 1, but these draw a long line; I want it to be a vector of length 1.

I am not sure if this math is correct. If I find the unitary vector of (-1,1,0) it is (-1,1,0)/(sqrt(2)) i.e. (-sqrt(2)/2,sqrt(2)/2,0) then I still do not have a vector of length 1 (when t is between 0 and 1).

Here is my MWE:

\documentclass{article}
\usepackage[a4paper,margin=1in,footskip=0.25in]{geometry}

\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\begin{document}

\begin{center}
\begin{tikzpicture}
\begin{axis} [
title={Without normalizing $(-1,1,0)$ ($t\in[0,1]$)},
axis on top,
axis lines=center,
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
ticklabel style={font=\tiny},
view={115}{25}
]
\addplot3[opacity=.5,surf,samples=21,variable=\t,variable y=\s,domain=0:2,y domain=0:90,z buffer=sort,colormap={red}{color=(red) color=(red)}] ({\t*cos(\s)*(sqrt(2)*.5)},{\t*cos(\s)*(sqrt(2)*.5)},{\t*sin(\s)});%Red S
\end{axis}
\end{tikzpicture}
\hfill
\begin{tikzpicture}
\begin{axis} [
title={Normalizing $(-1,1,0)$ ($t\in[0,1]$)},
axis on top,
axis lines=center,
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
ticklabel style={font=\tiny},
view={115}{25}
]
\addplot3[opacity=.5,surf,samples=21,variable=\t,variable y=\s,domain=0:2,y domain=0:90,z buffer=sort,colormap={red}{color=(red) color=(red)}] ({\t*cos(\s)*(sqrt(2)*.5)},{\t*cos(\s)*(sqrt(2)*.5)},{\t*sin(\s)});%Red S
\end{axis}
\end{tikzpicture}
\end{center}

\end{document}


Even the line has a bad quality, it looks pixelated:

Does anyone know how to produce a vector of length 1 or what am I missing?

Thanks!!

I hope I am not missing anything obvious. You only need to divide by sqrt(2) in your left example to arrive at

\documentclass{article}
\usepackage[a4paper,margin=1in,footskip=0.25in]{geometry}

\usepackage{pgfplots}
\pgfplotsset{compat=1.15}

\begin{document}

\begin{center}
\begin{tikzpicture}
\begin{axis} [
title={Normalizing},
axis on top,
axis lines=center,
xlabel=$x$,
ylabel=$y$,
zlabel=$z$,
ticklabel style={font=\tiny},
view={115}{25}
]
\addplot3[opacity=.5,surf,samples=21,variable=\t,variable y=\s,domain=0:2,y domain=0:90,z buffer=sort,colormap={red}{color=(red) color=(red)}] ({\t*cos(\s)*(sqrt(2)*.5)},{\t*cos(\s)*(sqrt(2)*.5)},{\t*sin(\s)});%Red S
\pgfmathsetmacro{\msq}{sqrt(1/2)}

The "pixelation" went away after adding samples y=0.
• @manooooh We add a vector in the xy-plane. This vector goes in the (1,-1) direction. The normalized vector in this direction is (1/sqrt(2),-1/sqrt(2))=(cos(-45),sin(-45)). – marmot Feb 26 at 19:09
• That is what I have done. I have used sqrt(2)/2 instead of 1/sqrt(2). – manooooh Feb 26 at 19:10
• @manooooh Because sqrt(2) is by a factor 2 too long. ;-) – marmot Feb 26 at 19:15
• @manooooh Yes, 1/sqrt(2) and sqrt(1/2) are the same. – marmot Feb 26 at 19:19