Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit decb556

Browse files
feat(geometry/euclidean/basic): lemmas about angles and distances (#7140)
Co-authored-by: Johan Commelin <johan@commelin.net>
1 parent ea379b0 commit decb556

File tree

1 file changed

+190
-1
lines changed

1 file changed

+190
-1
lines changed

src/geometry/euclidean/basic.lean

Lines changed: 190 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/-
22
Copyright (c) 2020 Joseph Myers. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
4-
Authors: Joseph Myers
4+
Authors: Joseph Myers, Manuel Candales
55
-/
66
import analysis.normed_space.inner_product
77
import algebra.quadratic_discriminant
@@ -233,6 +233,112 @@ them is π/2. -/
233233
lemma inner_eq_zero_iff_angle_eq_pi_div_two (x y : V) : ⟪x, y⟫ = 0 ↔ angle x y = π / 2 :=
234234
iff.symm $ by simp [angle, or_imp_distrib] { contextual := tt }
235235

236+
/-- If the angle between two vectors is π, the inner product equals the negative product
237+
of the norms. -/
238+
lemma inner_eq_neg_mul_norm_of_angle_eq_pi {x y : V} (h : angle x y = π) : ⟪x, y⟫ = - (∥x∥ * ∥y∥) :=
239+
by simp [← cos_angle_mul_norm_mul_norm, h]
240+
241+
/-- If the angle between two vectors is 0, the inner product equals the product of the norms. -/
242+
lemma inner_eq_mul_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) : ⟪x, y⟫ = ∥x∥ * ∥y∥ :=
243+
by simp [← cos_angle_mul_norm_mul_norm, h]
244+
245+
/-- The inner product of two non-zero vectors equals the negative product of their norms
246+
if and only if the angle between the two vectors is π. -/
247+
lemma inner_eq_neg_mul_norm_iff_angle_eq_pi {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
248+
⟪x, y⟫ = - (∥x∥ * ∥y∥) ↔ angle x y = π :=
249+
begin
250+
refine ⟨λ h, _, inner_eq_neg_mul_norm_of_angle_eq_pi⟩,
251+
have h₁ : (∥x∥ * ∥y∥) ≠ 0 := (mul_pos (norm_pos_iff.mpr hx) (norm_pos_iff.mpr hy)).ne',
252+
rw [angle, h, neg_div, div_self h₁, real.arccos_neg_one],
253+
end
254+
255+
/-- The inner product of two non-zero vectors equals the product of their norms
256+
if and only if the angle between the two vectors is 0. -/
257+
lemma inner_eq_mul_norm_iff_angle_eq_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
258+
⟪x, y⟫ = ∥x∥ * ∥y∥ ↔ angle x y = 0 :=
259+
begin
260+
refine ⟨λ h, _, inner_eq_mul_norm_of_angle_eq_zero⟩,
261+
have h₁ : (∥x∥ * ∥y∥) ≠ 0 := (mul_pos (norm_pos_iff.mpr hx) (norm_pos_iff.mpr hy)).ne',
262+
rw [angle, h, div_self h₁, real.arccos_one],
263+
end
264+
265+
/-- If the angle between two vectors is π, the norm of their difference equals
266+
the sum of their norms. -/
267+
lemma norm_sub_eq_add_norm_of_angle_eq_pi {x y : V} (h : angle x y = π) : ∥x - y∥ = ∥x∥ + ∥y∥ :=
268+
begin
269+
rw ← eq_of_sq_eq_sq (norm_nonneg (x - y)) (add_nonneg (norm_nonneg x) (norm_nonneg y)),
270+
rw [norm_sub_pow_two_real, inner_eq_neg_mul_norm_of_angle_eq_pi h],
271+
ring,
272+
end
273+
274+
/-- If the angle between two vectors is 0, the norm of their sum equals
275+
the sum of their norms. -/
276+
lemma norm_add_eq_add_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) : ∥x + y∥ = ∥x∥ + ∥y∥ :=
277+
begin
278+
rw ← eq_of_sq_eq_sq (norm_nonneg (x + y)) (add_nonneg (norm_nonneg x) (norm_nonneg y)),
279+
rw [norm_add_pow_two_real, inner_eq_mul_norm_of_angle_eq_zero h],
280+
ring,
281+
end
282+
283+
/-- If the angle between two vectors is 0, the norm of their difference equals
284+
the absolute value of the difference of their norms. -/
285+
lemma norm_sub_eq_abs_sub_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) :
286+
∥x - y∥ = abs (∥x∥ - ∥y∥) :=
287+
begin
288+
rw [← eq_of_sq_eq_sq (norm_nonneg (x - y)) (abs_nonneg (∥x∥ - ∥y∥)),
289+
norm_sub_pow_two_real, inner_eq_mul_norm_of_angle_eq_zero h, sq_abs (∥x∥ - ∥y∥)],
290+
ring,
291+
end
292+
293+
/-- The norm of the difference of two non-zero vectors equals the sum of their norms
294+
if and only the angle between the two vectors is π. -/
295+
lemma norm_sub_eq_add_norm_iff_angle_eq_pi {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
296+
∥x - y∥ = ∥x∥ + ∥y∥ ↔ angle x y = π :=
297+
begin
298+
refine ⟨λ h, _, norm_sub_eq_add_norm_of_angle_eq_pi⟩,
299+
rw ← inner_eq_neg_mul_norm_iff_angle_eq_pi hx hy,
300+
obtain ⟨hxy₁, hxy₂⟩ := ⟨norm_nonneg (x - y), add_nonneg (norm_nonneg x) (norm_nonneg y)⟩,
301+
rw [← eq_of_sq_eq_sq hxy₁ hxy₂, norm_sub_pow_two_real] at h,
302+
calc inner x y = (∥x∥ ^ 2 + ∥y∥ ^ 2 - (∥x∥ + ∥y∥) ^ 2) / 2 : by linarith
303+
... = -(∥x∥ * ∥y∥) : by ring,
304+
end
305+
306+
/-- The norm of the sum of two non-zero vectors equals the sum of their norms
307+
if and only the angle between the two vectors is 0. -/
308+
lemma norm_add_eq_add_norm_iff_angle_eq_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
309+
∥x + y∥ = ∥x∥ + ∥y∥ ↔ angle x y = 0 :=
310+
begin
311+
refine ⟨λ h, _, norm_add_eq_add_norm_of_angle_eq_zero⟩,
312+
rw ← inner_eq_mul_norm_iff_angle_eq_zero hx hy,
313+
obtain ⟨hxy₁, hxy₂⟩ := ⟨norm_nonneg (x + y), add_nonneg (norm_nonneg x) (norm_nonneg y)⟩,
314+
rw [← eq_of_sq_eq_sq hxy₁ hxy₂, norm_add_pow_two_real] at h,
315+
calc inner x y = ((∥x∥ + ∥y∥) ^ 2 - ∥x∥ ^ 2 - ∥y∥ ^ 2)/ 2 : by linarith
316+
... = ∥x∥ * ∥y∥ : by ring,
317+
end
318+
319+
/-- The norm of the difference of two non-zero vectors equals the absolute value
320+
of the difference of their norms if and only the angle between the two vectors is 0. -/
321+
lemma norm_sub_eq_abs_sub_norm_iff_angle_eq_zero {x y : V} (hx : x ≠ 0) (hy : y ≠ 0) :
322+
∥x - y∥ = abs (∥x∥ - ∥y∥) ↔ angle x y = 0 :=
323+
begin
324+
refine ⟨λ h, _, norm_sub_eq_abs_sub_norm_of_angle_eq_zero⟩,
325+
rw ← inner_eq_mul_norm_iff_angle_eq_zero hx hy,
326+
have h1 : ∥x - y∥ ^ 2 = (∥x∥ - ∥y∥) ^ 2, { rw h, exact sq_abs (∥x∥ - ∥y∥) },
327+
rw norm_sub_pow_two_real at h1,
328+
calc inner x y = ((∥x∥ + ∥y∥) ^ 2 - ∥x∥ ^ 2 - ∥y∥ ^ 2)/ 2 : by linarith
329+
... = ∥x∥ * ∥y∥ : by ring,
330+
end
331+
332+
/-- The norm of the sum of two vectors equals the norm of their difference if and only if
333+
the angle between them is π/2. -/
334+
lemma norm_add_eq_norm_sub_iff_angle_eq_pi_div_two (x y : V) :
335+
∥x + y∥ = ∥x - y∥ ↔ angle x y = π / 2 :=
336+
begin
337+
rw [← eq_of_sq_eq_sq (norm_nonneg (x + y)) (norm_nonneg (x - y)),
338+
← inner_eq_zero_iff_angle_eq_pi_div_two x y, norm_add_pow_two_real, norm_sub_pow_two_real],
339+
split; intro h; linarith,
340+
end
341+
236342
end inner_product_geometry
237343

238344
namespace euclidean_geometry
@@ -331,6 +437,89 @@ begin
331437
exact angle_add_angle_eq_pi_of_angle_eq_pi _ h
332438
end
333439

440+
/-- Vertical Angles Theorem: angles opposite each other, formed by two intersecting straight
441+
lines, are equal. -/
442+
lemma angle_eq_angle_of_angle_eq_pi_of_angle_eq_pi {p1 p2 p3 p4 p5 : P}
443+
(hapc : ∠ p1 p5 p3 = π) (hbpd : ∠ p2 p5 p4 = π) : ∠ p1 p5 p2 = ∠ p3 p5 p4 :=
444+
by linarith [angle_add_angle_eq_pi_of_angle_eq_pi p1 hbpd, angle_comm p4 p5 p1,
445+
angle_add_angle_eq_pi_of_angle_eq_pi p4 hapc, angle_comm p4 p5 p3]
446+
447+
/-- If ∠ABC = π then dist A B ≠ 0. -/
448+
lemma left_dist_ne_zero_of_angle_eq_pi {p1 p2 p3 : P} (h : ∠ p1 p2 p3 = π) : dist p1 p2 ≠ 0 :=
449+
begin
450+
by_contra heq,
451+
rw [not_not, dist_eq_zero] at heq,
452+
rw [heq, angle_eq_left] at h,
453+
exact real.pi_ne_zero (by linarith),
454+
end
455+
456+
/-- If ∠ABC = π then dist C B ≠ 0. -/
457+
lemma right_dist_ne_zero_of_angle_eq_pi {p1 p2 p3 : P} (h : ∠ p1 p2 p3 = π) : dist p3 p2 ≠ 0 :=
458+
left_dist_ne_zero_of_angle_eq_pi $ (angle_comm _ _ _).trans h
459+
460+
/-- If ∠ABC = π, then (dist A C) = (dist A B) + (dist B C). -/
461+
lemma dist_eq_add_dist_of_angle_eq_pi {p1 p2 p3 : P} (h : ∠ p1 p2 p3 = π) :
462+
dist p1 p3 = dist p1 p2 + dist p3 p2 :=
463+
begin
464+
rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right],
465+
exact norm_sub_eq_add_norm_of_angle_eq_pi h,
466+
end
467+
468+
/-- If A ≠ B and C ≠ B then ∠ABC = π if and only if (dist A C) = (dist A B) + (dist B C). -/
469+
lemma dist_eq_add_dist_iff_angle_eq_pi {p1 p2 p3 : P} (hp1p2 : p1 ≠ p2) (hp3p2 : p3 ≠ p2) :
470+
dist p1 p3 = dist p1 p2 + dist p3 p2 ↔ ∠ p1 p2 p3 = π :=
471+
begin
472+
rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right],
473+
exact norm_sub_eq_add_norm_iff_angle_eq_pi
474+
((λ he, hp1p2 (vsub_eq_zero_iff_eq.1 he))) (λ he, hp3p2 (vsub_eq_zero_iff_eq.1 he)),
475+
end
476+
477+
/-- If ∠ABC = 0, then (dist A C) = abs ((dist A B) - (dist B C)). -/
478+
lemma dist_eq_abs_sub_dist_of_angle_eq_zero {p1 p2 p3 : P} (h : ∠ p1 p2 p3 = 0) :
479+
(dist p1 p3) = abs ((dist p1 p2) - (dist p3 p2)) :=
480+
begin
481+
rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right],
482+
exact norm_sub_eq_abs_sub_norm_of_angle_eq_zero h,
483+
end
484+
485+
/-- If A ≠ B and C ≠ B then ∠ABC = 0 if and only if (dist A C) = abs ((dist A B) - (dist B C)). -/
486+
lemma dist_eq_abs_sub_dist_iff_angle_eq_zero {p1 p2 p3 : P} (hp1p2 : p1 ≠ p2) (hp3p2 : p3 ≠ p2) :
487+
(dist p1 p3) = abs ((dist p1 p2) - (dist p3 p2)) ↔ ∠ p1 p2 p3 = 0 :=
488+
begin
489+
rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right],
490+
exact norm_sub_eq_abs_sub_norm_iff_angle_eq_zero
491+
((λ he, hp1p2 (vsub_eq_zero_iff_eq.1 he))) (λ he, hp3p2 (vsub_eq_zero_iff_eq.1 he)),
492+
end
493+
494+
/-- The midpoint of the segment AB is the same distance from A as it is from B. -/
495+
lemma dist_left_midpoint_eq_dist_right_midpoint (p1 p2 : P) :
496+
dist p1 (midpoint ℝ p1 p2) = dist p2 (midpoint ℝ p1 p2) :=
497+
by rw [dist_left_midpoint p1 p2, dist_right_midpoint p1 p2]
498+
499+
/-- If M is the midpoint of the segment AB, then ∠AMB = π. -/
500+
lemma angle_midpoint_eq_pi (p1 p2 : P) (hp1p2 : p1 ≠ p2) : ∠ p1 (midpoint ℝ p1 p2) p2 = π :=
501+
have p2 -ᵥ midpoint ℝ p1 p2 = -(p1 -ᵥ midpoint ℝ p1 p2), by { rw neg_vsub_eq_vsub_rev, simp },
502+
by simp [angle, this, hp1p2]
503+
504+
/-- If M is the midpoint of the segment AB and C is the same distance from A as it is from B
505+
then ∠CMA = π / 2. -/
506+
lemma angle_left_midpoint_eq_pi_div_two_of_dist_eq {p1 p2 p3 : P} (h : dist p3 p1 = dist p3 p2) :
507+
∠ p3 (midpoint ℝ p1 p2) p1 = π / 2 :=
508+
begin
509+
let m : P := midpoint ℝ p1 p2,
510+
have h1 : p3 -ᵥ p1 = (p3 -ᵥ m) - (p1 -ᵥ m) := (vsub_sub_vsub_cancel_right p3 p1 m).symm,
511+
have h2 : p3 -ᵥ p2 = (p3 -ᵥ m) + (p1 -ᵥ m),
512+
{ rw [left_vsub_midpoint, ← midpoint_vsub_right, vsub_add_vsub_cancel] },
513+
rw [dist_eq_norm_vsub V p3 p1, dist_eq_norm_vsub V p3 p2, h1, h2] at h,
514+
exact (norm_add_eq_norm_sub_iff_angle_eq_pi_div_two (p3 -ᵥ m) (p1 -ᵥ m)).mp h.symm,
515+
end
516+
517+
/-- If M is the midpoint of the segment AB and C is the same distance from A as it is from B
518+
then ∠CMB = π / 2. -/
519+
lemma angle_right_midpoint_eq_pi_div_two_of_dist_eq {p1 p2 p3 : P} (h : dist p3 p1 = dist p3 p2) :
520+
∠ p3 (midpoint ℝ p1 p2) p2 = π / 2 :=
521+
by rw [midpoint_comm p1 p2, angle_left_midpoint_eq_pi_div_two_of_dist_eq h.symm]
522+
334523
/-- The inner product of two vectors given with `weighted_vsub`, in
335524
terms of the pairwise distances. -/
336525
lemma inner_weighted_vsub {ι₁ : Type*} {s₁ : finset ι₁} {w₁ : ι₁ → ℝ} (p₁ : ι₁ → P)

0 commit comments

Comments
 (0)