Перевод геометрических свойств в координаты
This commit is contained in:
29
Ковтун Богдан/Kovtun Bogdan.rkt
Normal file
29
Ковтун Богдан/Kovtun Bogdan.rkt
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
#lang racket/base
|
||||
(define (coordinations x1 y1 x2 y2 x3 y3 x4 y4 x5 y5)
|
||||
(define (square x) (* x x))
|
||||
(if (equal? (* (- x1 x2) (- y2 y3)) (* (- y1 y2) (- x2 x3)))
|
||||
(displayln "Points 1, 2 and 3 lie on a common line.")
|
||||
(displayln "Points 1, 2 and 3 do not lie on a common line."))
|
||||
(if (equal? (* (- x1 x2) (- y3 y4)) (* (- y1 y2) (- x3 x4)))
|
||||
(displayln "Lines (1,2) and (3,4) are parallel.")
|
||||
(displayln "Lines (1,2) and (3,4) are not parallel."))
|
||||
(if (equal? (+ (* (- x1 x2) (- x3 x4)) (* (- y1 y2) (- y3 y4))) 0 )
|
||||
(displayln "Lines (1,2) and (3,4) are perpendicular.")
|
||||
(displayln "Lines (1,2) and (3,4) are not perpendicular."))
|
||||
(if (equal? (+ (square(- x1 x2)) (square(- y1 y2))) (+ (square(- x3 x4)) (square(- y3 y4))))
|
||||
(displayln "Lines (1,2) and (3,4) have the same length.")
|
||||
(displayln "Lines (1,2) and (3,4) do not have the same length.."))
|
||||
(if (and (equal? (* 2 x1) (+ x2 x3)) (equal? (* 2 y1) (+ y2 y3)))
|
||||
(displayln "Point 1 is the midpoint of line (2,3).")
|
||||
(displayln "Point 1 is not the midpoint of line (2,3)."))
|
||||
(if (and (equal? (* (- x1 x2) (- y2 y3)) (* (- y1 y2) (- x2 x3)) )
|
||||
(equal? (* (- x1 x4) (- y4 y5)) (* (- y1 y4) (- x4 x5)) ) )
|
||||
(displayln "Lines (2,3) and (4,5) meet at point 1.")
|
||||
(displayln "Lines (2,3) and (4,5) do not intersect at point 1."))
|
||||
(if (and (equal? x1 x2) (equal? y1 y2))
|
||||
(displayln "Points 1 and 2 are the same.")
|
||||
(displayln "Points 1 and 2 are not the same."))
|
||||
|
||||
)
|
||||
(coordinations 0 1 0 0 0 1 1 1 2 2)
|
||||
32
Ковтун Богдан/README.md
Normal file
32
Ковтун Богдан/README.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# Перевод геометрических свойств в координаты
|
||||
## Ссылка на видеоразбор
|
||||
https://youtu.be/Nu43zpDrWuM
|
||||
## Код из книги
|
||||
let coordinations =
|
||||
["collinear", (** Points 1, 2 and 3 lie on a common line **)
|
||||
<<(1_x - 2_x) * (2_y - 3_y) = (1_y - 2_y) * (2_x - 3_x)>>;
|
||||
"parallel", (** Lines (1,2) and (3,4) are parallel **)
|
||||
<<(1_x - 2_x) * (3_y - 4_y) = (1_y - 2_y) * (3_x - 4_x)>>;
|
||||
"perpendicular", (** Lines (1,2) and (3,4) are perpendicular **)
|
||||
<<(1_x - 2_x) * (3_x - 4_x) + (1_y - 2_y) * (3_y - 4_y) = 0>>;
|
||||
"lengths_eq", (** Lines (1,2) and (3,4) have the same length **)
|
||||
<<(1_x - 2_x)^2 + (1_y - 2_y)^2 = (3_x - 4_x)^2 + (3_y - 4_y)^2>>;
|
||||
"is_midpoint", (** Point 1 is the midpoint of line (2,3) **)
|
||||
<<2 * 1_x = 2_x + 3_x /\ 2 * 1_y = 2_y + 3_y>>;
|
||||
"is_intersection", (** Lines (2,3) and (4,5) meet at point 1 **)
|
||||
<<(1_x - 2_x) * (2_y - 3_y) = (1_y - 2_y) * (2_x - 3_x) /\
|
||||
(1_x - 4_x) * (4_y - 5_y) = (1_y - 4_y) * (4_x - 5_x)>>;
|
||||
"=", (** Points 1 and 2 are the same **)
|
||||
<<(1_x = 2_x) /\ (1_y = 2_y)>>];;
|
||||
|
||||
let coordinate = onatoms
|
||||
(fun (R(a,args)) ->
|
||||
let xtms,ytms = unzip
|
||||
(map (fun (Var v) -> Var(v^"_x"),Var(v^"_y")) args) in
|
||||
let xs = map (fun n -> string_of_int n^"_x") (1--length args)
|
||||
and ys = map (fun n -> string_of_int n^"_y") (1--length args) in
|
||||
subst (fpf (xs @ ys) (xtms @ ytms)) (assoc a coordinations));;
|
||||
|
||||
START_INTERACTIVE;;
|
||||
coordinate <<collinear(a,b,c) ==> collinear(b,a,c)>>;;
|
||||
END_INTERACTIVE;;
|
||||
Reference in New Issue
Block a user