Graphics, Figures & TablestikZ | Quadratic Bézier Curves

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
x42bn6
Posts: 14
Joined: Tue Apr 07, 2009 1:35 am

tikZ | Quadratic Bézier Curves

Post by x42bn6 »

I love TikZ but does anyone know how to do a quadratic Bézier curve on it?

TikZ only provides support for cubic Bézier curves, which is one too much for me.

Failing that, does anyone know how to convert a cubic Bézier curve into a quadratic one?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

tikZ | Quadratic Bézier Curves

Post by localghost »

If you really need a quadratic Bézier curve on the points P0, P1 and P2, then a process called »degree elevation« yields the cubic control points (Q0, Q1, Q2 and Q3) as follows:

Code: Select all

Q0 = P0
Q1 = 1/3 P0 + 2/3 P1
Q2 = 2/3 P1 + 1/3 P2
Q3 = P2
A simple example looks like this.

Code: Select all

\documentclass{minimal}
\usepackage{tikz}

\begin{document}
  \begin{tikzpicture}
    \draw[help lines] (0,0) grid (3,1);
    \filldraw [gray] (0,0) circle (2pt)
                     (2,1) circle (2pt)
                     (3,0) circle (2pt);
    \draw (0,0) .. controls (1.334,0.667) and (2.334,0.667) .. (3,0);
  \end{tikzpicture}
\end{document}
This reduces the Bézier curve from cubic to quadratic.


Best regards and welcome to the board
Thorsten¹
Atrix256
Posts: 1
Joined: Mon Jun 22, 2015 7:31 pm

Re: tikZ | Quadratic Bézier Curves

Post by Atrix256 »

Another way to do this is to plot the function of a quadratic bezier curve in Bernstein form.

a 1d explicit quadratic bezier function looks like this:

y = A*(1-x)^2 + B*2x(1-x) + C*x^2

I just did that to get a 1d bezier curve diagram for my paper. Not sure if tikZ can plot multi-dimensional functions or not where f(x,y)=0, but if so, you just have one of those explicit 1d bezier curves per axis, where A,B,C are the control points for that specific axis.

If it helps, here's how to draw a 1d quadratic bezier curve with control points 0,1,0

\draw[scale=1,domain=0:1,smooth,variable=\x,blue] plot ({\x},{2*\x-2*\x*\x});
Post Reply