2023-04-10 16:15:52 +00:00
|
|
|
---
|
|
|
|
title: Point.slope()
|
|
|
|
---
|
|
|
|
|
2025-05-19 17:20:45 -07:00
|
|
|
The `Point.slope()` method returns the slope (dy/dx) of a line between two Points.
|
2023-04-10 16:15:52 +00:00
|
|
|
|
|
|
|
## Signature
|
|
|
|
|
|
|
|
```js
|
2023-04-16 16:39:13 +00:00
|
|
|
|
|
|
|
point.slope(otherPoint)
|
|
|
|
|
2023-04-10 16:15:52 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
<Example caption="An example of the Point.slope() method">
|
2023-04-16 16:39:13 +00:00
|
|
|
|
2023-04-10 16:15:52 +00:00
|
|
|
```js
|
2023-04-16 16:39:13 +00:00
|
|
|
|
2023-04-16 16:51:14 +00:00
|
|
|
({ Point, points, Path, paths, Snippet, snippets, part, macro }) => {
|
2023-04-10 16:15:52 +00:00
|
|
|
|
2023-04-16 16:39:13 +00:00
|
|
|
points.A = new Point(0,0)
|
2023-04-16 16:51:14 +00:00
|
|
|
points.B = new Point(200,150)
|
2023-04-16 16:39:13 +00:00
|
|
|
|
|
|
|
const slope = points.A.slope(points.B)
|
|
|
|
|
2023-04-16 16:51:14 +00:00
|
|
|
macro('hd', {
|
|
|
|
from: points.A,
|
|
|
|
to: points.B,
|
|
|
|
y: points.B.y,
|
2025-05-19 17:20:45 -07:00
|
|
|
id: 'macro1',
|
|
|
|
force: true,
|
2023-04-16 16:51:14 +00:00
|
|
|
})
|
|
|
|
macro('vd', {
|
|
|
|
to: points.B,
|
|
|
|
from: points.A,
|
|
|
|
x: 0,
|
2025-05-19 17:20:45 -07:00
|
|
|
id: 'macro2',
|
|
|
|
force: true,
|
2023-04-16 16:51:14 +00:00
|
|
|
})
|
|
|
|
|
2023-04-16 16:39:13 +00:00
|
|
|
paths.line = new Path()
|
|
|
|
.move(points.A)
|
|
|
|
.line(points.B)
|
|
|
|
.attr("class", "canvas")
|
2023-04-16 16:51:14 +00:00
|
|
|
.setText("Slope: " + slope, "center text-lg")
|
|
|
|
|
2023-04-10 16:15:52 +00:00
|
|
|
return part
|
|
|
|
}
|
2023-04-16 16:39:13 +00:00
|
|
|
|
2023-04-10 16:15:52 +00:00
|
|
|
```
|
|
|
|
</Example>
|