BRAGA

02 Writing02-02 Notes02-02-180

Ellipse

Published 16 Apr 20269 min read
Contents
  1. 01Deep Breakdown
  2. 02Flowchart
  3. 03Real-world use
  4. 04The formula, piece by piece
  5. 05The formula in words
  6. 06Critical Concepts
  7. 07Step-by-step calculation (tiny example)
  8. 08Code examples
x2a2+y2b2=1\frac{x^2}{a^2} + \frac{y^2}{b^2} = 1
(1)

, A=πabA = \pi a b

Deep Breakdown

What it tells me (Situation Awareness): The ellipse x2a2+y2b2=1\frac{x^2}{a^2} + \frac{y^2}{b^2} = 1 is the set of points where the sum of distances to two fixed foci is constant. With semi-major axis aa (along xx) and semi-minor axis bb (along yy), the area is A=πabA = \pi a b. The circle is the special case a=b=Ra = b = R. In DA/DS and statistics, the ellipse is the confidence region shape for a bivariate normal distribution: the 1-σ\sigma contour of N(μ,Σ)\mathcal{N}(\mu, \Sigma) in 2D is an ellipse whose axes align with the eigenvectors of Σ\Sigma and whose half-axes lengths are λ1\sqrt{\lambda_1} and λ2\sqrt{\lambda_2} (the square roots of the eigenvalues). PCA scatter plots routinely overlay these confidence ellipses to visualize data spread and feature correlation.

Flowchart

a bb aa == bBivariate NormalPCACovariance visualizationEllipse centeredat origin withsemi-axes a (x)and b (y)Equation:x^2/a^2 +y^2/b^2 = 1Area: A = pi * a *bWhat is theshape?Wider alongx-axis (prolate inx direction)Taller alongy-axis (prolate iny direction)Circle (specialcase)DA/DSconnectionSigma = [[a^2,rho*a*b],[rho*a*b, b^2]] -confidenceellipseEigenvectors ofSigma = ellipseaxes,sqrt(eigenvalues) = half-axesEllipse area = pi*sqrt(det(Sigma))(proportional)

Real-world use

Where it is used

Used when plotting confidence regions for bivariate normal distributions in 2D (PCA biplots, scatter plot overlays), in orbital mechanics analogies for understanding non-circular feature distributions, in quality control (Hotelling's T2T^2 statistic defines an ellipsoidal acceptance region), and in 2D anomaly detection where the normal region is an ellipse defined by the covariance structure of the training data.

Problem it solves

A circle assumes equal variance in all directions. Real data rarely has this property: feature pairs often have different scales and may be correlated. The ellipse generalizes the circle to capture anisotropic (direction-dependent) spread, making it the correct geometric object for modeling 2D Gaussian data, defining confidence regions, and visualizing correlation structure.

How it solves the problem

The ellipse equation x2a2+y2b2=1\frac{x^2}{a^2} + \frac{y^2}{b^2} = 1 is the standard form aligned with the coordinate axes. For a rotated ellipse (correlated features), the general form is xTΣ−1x=c2\mathbf{x}^T \Sigma^{-1} \mathbf{x} = c^2 where Σ\Sigma is the covariance matrix. Eigendecomposing Σ=QΛQT\Sigma = Q\Lambda Q^T gives the rotation angle (eigenvectors QQ) and the axis lengths (λi\sqrt{\lambda_i} scaled by cc). The area formula A=πabA = \pi a b follows from the substitution u=x/au = x/a, v=y/bv = y/b which transforms the ellipse to the unit circle with Jacobian abab.

Example in a business

A data scientist plots the scatter of weekly TV spend vs digital spend for 104 weeks, overlaid with the 95% confidence ellipse from the sample covariance matrix. The ellipse's tilt reveals the correlation direction; the axis lengths reveal the relative variability. If the ellipse is nearly circular, the two channels vary independently; if it is elongated, the channels co-vary (possibly due to budget constraints or seasonality). This informs media mix model assumptions.

The formula, piece by piece

  • x2a2\frac{x^2}{a^2}: the contribution of the xx-coordinate, normalized by the squared semi-major axis aa; aa controls the horizontal extent
  • y2b2\frac{y^2}{b^2}: the contribution of the yy-coordinate, normalized by the squared semi-minor axis bb; bb controls the vertical extent
  • aa: semi-major axis length; half the width along the xx-axis; a≥ba \geq b by convention
  • bb: semi-minor axis length; half the height along the yy-axis
  • A=πabA = \pi a b: area; reduces to πr2\pi r^2 when a=b=ra = b = r
  • Eccentricity: e=1−b2/a2e = \sqrt{1 - b^2/a^2} (0 = circle, approaching 1 = very elongated) Full formulas: x2a2+y2b2=1\dfrac{x^2}{a^2} + \dfrac{y^2}{b^2} = 1, A=πabA = \pi a b

The formula in words

"An ellipse is a stretched circle: squash a circle by factor b/ab/a in the yy-direction and you get an ellipse with semi-axes aa and bb. The area is π\pi times both half-axis lengths — if either half-axis is rr, you recover the circle formula πr2\pi r^2." Tiny numeric example: a=5a = 5, b=3b = 3. Equation: x225+y29=1\frac{x^2}{25} + \frac{y^2}{9} = 1. Points on ellipse: (5,0)(5, 0) (right vertex), (0,3)(0, 3) (top vertex), (−5,0)(-5, 0), (0,−3)(0, -3). A=π⋅5⋅3=15π≈47.12A = \pi \cdot 5 \cdot 3 = 15\pi \approx 47.12.

Critical Concepts

  • Standard vs general form: standard form assumes axes aligned with coordinate axes. For a rotated/correlated ellipse: xTΣ−1x=k2\mathbf{x}^T \Sigma^{-1} \mathbf{x} = k^2 where k2=χ2,1−α2k^2 = \chi^2_{2, 1-\alpha} (from chi-squared distribution with 2 df) for a (1−α)(1-\alpha) confidence region.
  • Confidence region for bivariate normal: the pp-level confidence ellipse has k2=χ22(p)k^2 = \chi^2_{2}(p). For 95%, k2≈5.991k^2 \approx 5.991.
  • Axis alignment from PCA: eigendecompose Σ=QΛQT\Sigma = Q\Lambda Q^T; the eigenvectors give the ellipse orientation, and λi⋅k2\sqrt{\lambda_i \cdot k^2} gives the half-axis lengths.
  • Area connection to determinant: Aconfidence region=πk2det⁡(Σ)A_{\text{confidence region}} = \pi k^2 \sqrt{\det(\Sigma)}. The determinant of the covariance matrix controls the total area of the confidence ellipse.
  • Eccentricity: e=0e = 0 is a circle; e→1e \to 1 is an extremely elongated ellipse. High eccentricity in a confidence ellipse signals strong correlation between the two features.
  • Perimeter: there is no simple closed-form for the ellipse perimeter (unlike area).

The Ramanujan approximation: C≈π[3(a+b)−(3a+b)(a+3b)]C \approx \pi[3(a+b) - \sqrt{(3a+b)(a+3b)}].

Step-by-step calculation (tiny example)

Step 1: Write the equation and identify vertices a=4a = 4, b=2b = 2. Equation: x216+y24=1\frac{x^2}{16} + \frac{y^2}{4} = 1. Vertices: (4,0)(4, 0), (−4,0)(-4, 0), (0,2)(0, 2), (0,−2)(0, -2). Foci: c=a2−b2=12≈3.46c = \sqrt{a^2 - b^2} = \sqrt{12} \approx 3.46 along xx: (±3.46,0)(\pm 3.46, 0).

Step 2: Compute the area A=π⋅4⋅2=8π≈25.13A = \pi \cdot 4 \cdot 2 = 8\pi \approx 25.13.

Step 3: Check a point is on the ellipse Point (22,2)(2\sqrt{2}, \sqrt{2}): (22)216+(2)24=816+24=0.5+0.5=1\frac{(2\sqrt{2})^2}{16} + \frac{(\sqrt{2})^2}{4} = \frac{8}{16} + \frac{2}{4} = 0.5 + 0.5 = 1.

Code examples

Beginner example (Python)

python
import numpy as np
import matplotlib.pyplot as plt

# -- Ellipse: equation, points on boundary, area -----------------------
A_SEMI = 5.0   # semi-major axis (x direction)
B_SEMI = 3.0   # semi-minor axis (y direction)

# Parametric form: x = a*cos(t), y = b*sin(t)
t = np.linspace(0, 2 * np.pi, 500)
x_ellipse = A_SEMI * np.cos(t)
y_ellipse = B_SEMI * np.sin(t)

# Check a few specific points
test_points = np.array([[5.0, 0.0], [0.0, 3.0], [3.0, 2.4]])
for pt in test_points:
    val = (pt[0] / A_SEMI)**2 + (pt[1] / B_SEMI)**2
    status = "on ellipse" if np.isclose(val, 1.0) else ("inside" if val < 1 else "outside")
    print(f" Point ({pt[0]:.1f}, {pt[1]:.1f}): x^2/a^2 + y^2/b^2 = {val:.4f} -> {status}")

area = np.pi * A_SEMI * B_SEMI
eccentricity = np.sqrt(1 - (B_SEMI / A_SEMI)**2)
print(f"\nSemi-axes: a={A_SEMI}, b={B_SEMI}")
print(f"Area A = pi*a*b = {area:.4f}")
print(f"Eccentricity e = {eccentricity:.4f} (0=circle, ~1=very elongated)")

Beginner example (R)

r
# -- Ellipse: equation, points on boundary, area -----------------------
A_SEMI <- 5.0
B_SEMI <- 3.0

# Parametric form
t <- seq(0, 2 * pi, length.out = 500)
x_ell <- A_SEMI * cos(t)
y_ell <- B_SEMI * sin(t)

# Check points
test_pts <- rbind(c(5, 0), c(0, 3), c(3, 2.4))
for (i in seq_len(nrow(test_pts))) {
  pt <- test_pts[i, ]
  val <- (pt[1] / A_SEMI)^2 + (pt[2] / B_SEMI)^2
  status <- if (isTRUE(all.equal(val, 1.0))) "on ellipse" else if (val < 1) "inside" else "outside"
  cat(sprintf(" Point (%.1f, %.1f): val = %.4f -> %s\n", pt[1], pt[2], val, status))
}
area <- pi * A_SEMI * B_SEMI
eccentricity <- sqrt(1 - (B_SEMI / A_SEMI)^2)
cat(sprintf("\nArea A = pi*a*b = %.4f\n", area))
cat(sprintf("Eccentricity e = %.4f\n", eccentricity))

Professional example (Python)

python
import numpy as np
import pandas as pd
from scipy.stats import chi2
np.random.seed(42)   # -- Business scenario: 95% confidence ellipse for weekly media spend
# TV spend and digital spend for 104 weeks.
# Overlay the 95% confidence ellipse (chi-squared with 2 df) on the scatter.
# Report: semi-axes, area, eccentricity, and what the ellipse shape reveals.
N_WEEKS = 104
TV_MEAN, TV_STD = 20_000.0, 4_000.0
DIGITAL_MEAN, DIG_STD = 15_000.0, 3_000.0
CORRELATION = 0.65   # positive: both channels funded together # Simulate correlated spend data
cov_raw = np.array([ [TV_STD**2, CORRELATION * TV_STD * DIG_STD], [CORRELATION * TV_STD * DIG_STD, DIG_STD**2],
])
spend = np.random.multivariate_normal([TV_MEAN, DIGITAL_MEAN], cov_raw, size=N_WEEKS)
x_centered = spend - spend.mean(axis=0)   # Sample covariance matrix
cov_sample = np.cov(x_centered.T)   # 2x2 # Confidence ellipse: x^T Sigma^-1 x = chi2(2, 0.95) ~ 5.991
K_SQ = float(chi2.ppf(0.95, df=2))
eigvals, eigvecs = np.linalg.eigh(cov_sample)
# Sort eigenvalues descending
order = np.argsort(eigvals)[::-1]
eigvals = eigvals[order]
eigvecs = eigvecs[:, order]   # Ellipse semi-axes in original units
semi_a = float(np.sqrt(eigvals[0] * K_SQ))   # semi-major axis (along eigvec_0)
semi_b = float(np.sqrt(eigvals[1] * K_SQ))   # semi-minor axis (along eigvec_1)
area = np.pi * semi_a * semi_b
angle_deg = float(np.degrees(np.arctan2(eigvecs[1, 0], eigvecs[0, 0])))
eccentricity = float(np.sqrt(1 - (semi_b / semi_a)**2))
summary = pd.DataFrame({ "metric": [ "semi-major axis (EUR)", "semi-minor axis (EUR)", "rotation angle (deg)", "confidence ellipse area (EUR^2)", "eccentricity", "correlation implied", ], "value": [ f"{semi_a:,.0f}", f"{semi_b:,.0f}", f"{angle_deg:.2f}", f"{area:,.0f}", f"{eccentricity:.4f}", f"{CORRELATION:.2f}", ],
})
print(f"95% Confidence Ellipse for TV vs Digital Spend (chi2 threshold = {K_SQ:.3f}):")
print(summary.to_string(index=False))
print(f"\nInterpretation: eccentricity={eccentricity:.3f} confirms strong elongation along the TV-digital correlation axis. The ellipse tilt of {angle_deg:.1f} degrees reflects the positive correlation of {CORRELATION}. Area = pi * {semi_a:,.0f} * {semi_b:,.0f} = {area:,.0f} EUR^2 (not a physical unit, but proportional to total data spread).")

Source: 1300 p. 160

#linear-algebra#spatial-distance-norms-and-analytic-geometry#analytic-geometry-shapes-perimeter-area-volume

Keyboard shortcuts

Single keys, ignored while typing in a field or with Cmd, Ctrl or Alt held.

0
Home
1 2 3 4
Work, Writing, Tools, About
j / k
Next / previous section on this page
n / p
Next / previous project or essay
u
Up one level
l
Deutsch
t
Light or dark theme
?
This list
Esc
Close