2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-10-16 15:42:30 +02:00
|
|
|
title: Point.rotate()
|
2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-09-29 16:05:17 +02:00
|
|
|
The `Point.rotate()` method returns a new `Point` that has been rotated by
|
|
|
|
`angle` degrees around the point (`center`) that you pass it.
|
2021-10-16 15:42:30 +02:00
|
|
|
|
2022-09-29 16:05:17 +02:00
|
|
|
Just like the result of the [`Point.angle()`](/reference/api/point/angle/)
|
|
|
|
method, an angle of 0° points right, and the angle increases counterclockwise.
|
2021-10-16 15:42:30 +02:00
|
|
|
|
2022-09-29 16:05:17 +02:00
|
|
|
## Signature
|
2021-11-06 19:03:54 +01:00
|
|
|
|
2021-08-25 16:09:31 +02:00
|
|
|
```js
|
|
|
|
Point point.rotate(float angle, Point center)
|
2021-10-16 15:42:30 +02:00
|
|
|
```
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-09-29 16:05:17 +02:00
|
|
|
## Example
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-12-08 22:37:22 -08:00
|
|
|
<Example caption="An example of the Point.rotate() method">
|
2021-08-25 16:09:31 +02:00
|
|
|
```js
|
2022-09-29 16:05:17 +02:00
|
|
|
({ Point, points, Path, paths, Snippet, snippets, part }) => {
|
|
|
|
|
2022-09-29 16:50:42 +02:00
|
|
|
points.sun = new Point(40, 40)
|
|
|
|
points.moon = new Point(70, 40)
|
|
|
|
let step = 360 / 36
|
2022-09-29 16:05:17 +02:00
|
|
|
for (let i = 1; i < 37; i++) {
|
2022-09-29 16:50:42 +02:00
|
|
|
let angle = step * i
|
|
|
|
points[`moon${i}`] = points.moon.rotate(angle, points.sun)
|
|
|
|
paths[`moon${i}`] = new Path().move(points.sun).line(points[`moon${i}`])
|
2022-09-29 16:05:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return part
|
2021-08-25 16:09:31 +02:00
|
|
|
}
|
|
|
|
```
|
2022-09-29 16:05:17 +02:00
|
|
|
</Example>
|