SimpleGFX  1.0
Simple Graphics Library for C Programming Education
m-parabola.c File Reference

Visualizing quadratic equations and parabolic curves. More...

#include "gfx/simplegfx.h"

Functions

int main ()
 

Detailed Description

Visualizing quadratic equations and parabolic curves.

Author
Sukesh Ashok Kumar

This example demonstrates the classic U-shaped curve of a parabola, defined by a quadratic equation. Parabolas appear everywhere in physics (projectile motion), engineering (suspension bridges), and mathematics.

Mathematical Concepts:

  • Quadratic equation: y = ax² + bx + c (standard form)
  • Coefficient 'a': determines width and direction (opens up if a>0, down if a<0)
  • Coefficient 'b': controls horizontal shift/tilt
  • Coefficient 'c': vertical shift (y-intercept)
  • Vertex: the turning point of the parabola (minimum or maximum)
  • Axis of symmetry: vertical line through vertex
  • Polynomial growth: quadratic (order 2) grows faster than linear

In This Example:

  • a = 0.02 (small positive value creates wide, upward-opening parabola)
  • b = 0 (no tilt, perfectly symmetric)
  • c = 400 (vertex near bottom of screen, opens upward)
  • Centered at x = 320 (middle of window)

Parabola Properties:

  • Vertex form: y = a(x - h)² + k where (h,k) is the vertex
  • Our vertex: (320, 400) in screen coordinates
  • Axis of symmetry: x = 320 (vertical line through center)
  • Opens upward because a > 0

Programming Concepts:

  • Using floating-point (double) for coefficient precision
  • Coordinate transformation (centering)
  • Boundary checking to prevent drawing outside window
  • Mixed integer and floating-point arithmetic
  • Quadratic growth: output changes faster as x increases

What you'll learn:

  • How quadratic equations create curved shapes
  • The effect of coefficients a, b, c on parabola shape
  • Why parabolas are symmetric
  • Converting continuous functions to discrete pixels
  • Boundary checking for valid screen coordinates
  • The difference between linear and quadratic growth

The Quadratic Formula: For y = ax² + bx + c:

  • When x = 0: y = c (y-intercept)
  • When x increases, x² term dominates (exponential growth)
  • Symmetric: f(h + d) = f(h - d) when b = 0

Experiment Ideas:

  • Change a to 0.01: wider parabola
  • Change a to -0.02: opens downward
  • Change c to 100: shifts parabola up
  • Change b to 1: tilts the parabola

Compile:

gcc m-parabola.c gfx/simplegfx.c -o output/m-parabola -lX11

Run:

./output/m-parabola

Function Documentation

◆ main()

int main ( )