Skip to content

Commit 112bdb0

Browse files
committed
cartesian-point-distance
1 parent 2149f23 commit 112bdb0

13 files changed

+236
-7
lines changed

Writerside/Geometry.tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,10 @@
1313
<toc-element topic="number-line-segment.md"/>
1414
<toc-element topic="number-line-segment-intersect.md"/>
1515
</toc-element>
16+
<toc-element topic="cartesian-coordinate-system.md">
17+
<toc-element topic="cartesian-point-distance.md"/>
18+
<toc-element topic="cartesian-line.md"/>
19+
<toc-element topic="cartesian-line-equation.md"/>
20+
</toc-element>
1621
<toc-element topic="donate.md"/>
1722
</instance-profile>

Writerside/cfg/buildprofiles.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,18 @@
3535
<include-in-head>js/core/color.js</include-in-head>
3636
<include-in-head>js/core/grid.js</include-in-head>
3737
<include-in-head>js/core/point.js</include-in-head>
38+
3839
<include-in-head>js/example/number-line.js</include-in-head>
3940
<include-in-head>js/example/number-line-abs.js</include-in-head>
4041
<include-in-head>js/example/number-line-distance.js</include-in-head>
4142
<include-in-head>js/example/number-line-segment.js</include-in-head>
4243
<include-in-head>js/example/number-line-segment-intersect.js</include-in-head>
4344

45+
<include-in-head>js/example/cartesian-coordinate-system.js</include-in-head>
46+
<include-in-head>js/example/cartesian-point-distance-a.js</include-in-head>
47+
<include-in-head>js/example/cartesian-point-distance-b.js</include-in-head>
48+
<include-in-head>js/example/cartesian-line.js</include-in-head>
49+
4450
<include-in-head>js/core/observe.js</include-in-head>
4551
<include-in-head>js/head-end.html</include-in-head>
4652

Writerside/cfg/js/core/grid.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,13 +418,13 @@ class CanvasGrid extends HTMLElement {
418418
* @param {Point} a
419419
* @param {Point} b
420420
* @param {number[]} dash
421-
* @param {boolean} line
421+
* @param {Color?} line
422422
* @param {Color} color
423423
* @return {this}
424424
*/
425425
segment(a, b, {
426426
dash = [],
427-
line = false,
427+
line = null,
428428
color = Color.yellow,
429429
} = {}) {
430430
const dpr = window.devicePixelRatio ?? 1
@@ -460,11 +460,11 @@ class CanvasGrid extends HTMLElement {
460460
ctx.stroke()
461461
ctx.closePath()
462462

463-
if (line) {
463+
if (line !== null) {
464464
const ld = Math.max(this.canvas.width, this.canvas.height) * 10
465465

466466
ctx.beginPath()
467-
ctx.strokeStyle = Colors.point.track.fill
467+
ctx.strokeStyle = line.strokeStyle
468468
let cos = Math.cos(angle)
469469
let sin = Math.sin(angle)
470470
ctx.moveTo(cos * r + bx, sin * r + by)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class CartesianCoordinateSystem extends CanvasGrid {
2+
static name = 'cartesian-coordinate-system'
3+
4+
get height() {
5+
return 12
6+
}
7+
8+
constructor() {
9+
super()
10+
11+
this
12+
.roundInit(false)
13+
.points.push(
14+
new Point(5, 3),
15+
)
16+
}
17+
18+
draw() {
19+
this.grid().dragRelease()
20+
21+
const [A] = this.points
22+
23+
for (const p of this.points) p.round = this.round
24+
25+
this.point(A, {trackX: true, trackY: true, name: 'A'})
26+
}
27+
}
28+
29+
CanvasGrid.define(CartesianCoordinateSystem)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
class CartesianLine extends CanvasGrid {
2+
static name = 'canvas-cartesian-line'
3+
4+
get height() {
5+
return 12
6+
}
7+
8+
constructor() {
9+
super()
10+
11+
this
12+
.roundInit(false)
13+
.points.push(
14+
new Point(2, 3),
15+
new Point(-2, 1),
16+
)
17+
}
18+
19+
draw() {
20+
this.grid().dragRelease()
21+
22+
const [A, B] = this.points
23+
24+
for (const p of this.points) p.round = this.round
25+
26+
this
27+
.point(A, {trackX: true, trackY: true, name: 'A'})
28+
.point(B, {trackX: true, trackY: true, name: 'B'})
29+
.segment(A, B, {line: Color.yellow})
30+
}
31+
}
32+
33+
CanvasGrid.define(CartesianLine)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
class CartesianPointDistanceA extends CanvasGrid {
2+
static name = 'canvas-cartesian-point-distance-a'
3+
4+
get height() {
5+
return 14
6+
}
7+
8+
constructor() {
9+
super()
10+
11+
this
12+
.roundInit(false)
13+
.points.push(
14+
new Point(4, 3),
15+
)
16+
}
17+
18+
draw() {
19+
this.grid().dragRelease()
20+
21+
const [A] = this.points
22+
23+
const O = new Point(0, 0)
24+
25+
A.round = O.round = this.round
26+
27+
const d = Math.sqrt(A.x * A.x + A.y * A.y)
28+
29+
30+
this
31+
.point(A, {trackX: true, trackY: true, name: 'A'})
32+
.point(O, {name: '(0,0)', dash: [2, 2]})
33+
.segment(A, O, {dash: [2, 2]})
34+
.text(`Расстояние ${d.toFixed(2)}`, {x: 0, y: 4})
35+
}
36+
}
37+
38+
CanvasGrid.define(CartesianPointDistanceA)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
class CartesianPointDistanceB extends CanvasGrid {
2+
static name = 'canvas-cartesian-point-distance-b'
3+
4+
get height() {
5+
return 16
6+
}
7+
8+
constructor() {
9+
super()
10+
11+
this
12+
.roundInit(false)
13+
.points.push(
14+
new Point(3, -2),
15+
new Point(6, -6),
16+
)
17+
}
18+
19+
draw() {
20+
this.grid().dragRelease()
21+
22+
const [A, B] = this.points
23+
24+
for (const p of this.points) p.round = this.round
25+
26+
const dx = B.x - A.x
27+
const dy = B.y - A.y
28+
29+
const d = Math.sqrt(dx * dx + dy * dy)
30+
31+
const A1 = new Point(0, 0)
32+
const B1 = new Point(dx, dy)
33+
34+
A1.round = this.round
35+
36+
this
37+
.point(A1, {name: 'A′', dash: [2, 2]})
38+
.point(B1, {name: 'B′', dash: [2, 2]})
39+
.segment(A1, B1, {dash: [2, 2]})
40+
41+
.point(A, {trackX: true, trackY: true, name: 'A'})
42+
.point(B, {trackX: true, trackY: true, name: 'B'})
43+
44+
.segment(A, B)
45+
.text(`Расстояние ${d.toFixed(2)}`, {x: 0, y: 5})
46+
}
47+
}
48+
49+
CanvasGrid.define(CartesianPointDistanceB)

Writerside/cfg/js/example/test.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
:root {
88
color-scheme: dark;
99
}
10+
1011
html, body {
1112
background-color: #252528;
1213
}
@@ -23,13 +24,18 @@
2324
<script type="text/javascript" src="number-line-segment.js"></script>
2425
<script type="text/javascript" src="number-line-segment-intersect.js"></script>
2526

27+
28+
<script type="text/javascript" src="cartesian-line.js"></script>
29+
<script type="text/javascript" src="cartesian-point-distance-a.js"></script>
30+
<script type="text/javascript" src="cartesian-point-distance-b.js"></script>
31+
32+
2633
<script type="text/javascript" src="../core/observe.js"></script>
2734
</head>
2835

2936
<body>
3037

31-
32-
<div id="canvas-number-line-segment-intersect"></div>
38+
<div id="canvas-cartesian-point-distance-b"></div>
3339

3440
</body>
3541

Writerside/cfg/js/head-start.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!--suppress CssUnusedSymbol -->
22
<style>
3-
div.h1-related > .MathJax {
3+
div.h1-related > .MathJax,
4+
div.h2-related > .MathJax {
45
display: flex;
56
align-items: center;
67
justify-content: center;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<show-structure for="chapter,procedure" depth="3"/>
2+
3+
# Декартова система координат
4+
5+
Система координат, которая позволяет однозначным образом определить каждую точку на плоскости с помощью пары числовых
6+
координат.
7+
8+
```.``` {id=cartesian-coordinate-system}
9+
10+
> Была придумана Рене Декартом *(René Descartes)*, чьё латинизированное имя Renatus Cartesius. Посему в англоязычных
11+
> источниках она называется *Cartesian coordinate system*.
12+
13+
## Оси {id="axis"}
14+
15+
По сути — две [числовые прямые](number-line.md), которые пересекаются в точке $(0,0)$ под прямым углом:
16+
17+
- горизонтальная ось $X$, растёт слева направо
18+
- вертикальная ось $Y$, растёт снизу вверх
19+
20+
При записи координаты, значение по оси $X$ записывают первым:
21+
22+
$$
23+
A(x,y)
24+
$$
25+
26+

0 commit comments

Comments
 (0)