2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-11-06 18:20:45 +01:00
|
|
|
title: Point.shiftFractionTowards()
|
2021-10-17 18:26:00 +02:00
|
|
|
---
|
2021-08-25 16:09:31 +02:00
|
|
|
|
2022-09-29 16:15:17 +02:00
|
|
|
The `Point.shiftFractionTowards()` method returns a new `Point` that is shifted
|
|
|
|
towards the `target` by a `fraction` of the distance between this point and the
|
|
|
|
target.
|
2021-11-06 18:20:45 +01:00
|
|
|
|
2022-09-29 16:15:17 +02:00
|
|
|
This method accepts values larger than 1 to go beyond the target point, or
|
|
|
|
negative values to shift the point in the opposite direction.
|
2021-11-06 18:20:45 +01:00
|
|
|
|
2022-09-29 16:15:17 +02:00
|
|
|
## Signature
|
2021-11-06 19:03:54 +01:00
|
|
|
|
2021-08-25 16:09:31 +02:00
|
|
|
```js
|
|
|
|
Point point.shiftFractionTowards(Point target, float fraction)
|
|
|
|
```
|
|
|
|
|
2021-11-06 19:03:54 +01:00
|
|
|
## Point.shiftFractionTowards() example
|
|
|
|
|
2022-09-29 16:15:17 +02:00
|
|
|
<Example caption="An example of the Point.shiftFractionTowards() method">
|
2021-08-25 16:09:31 +02:00
|
|
|
```js
|
2022-09-29 16:15:17 +02:00
|
|
|
({ Point, points, Path, paths, macro, part }) => {
|
|
|
|
|
2022-09-29 16:50:42 +02:00
|
|
|
points.A = new Point(90, 70).setText("Point A", "text-sm")
|
|
|
|
points.B = new Point(10, 10).setText("Point B", "text-sm")
|
2022-09-29 16:15:17 +02:00
|
|
|
points.C = points.A.shiftFractionTowards(points.B, 0.5)
|
2022-09-29 16:50:42 +02:00
|
|
|
.setText(
|
|
|
|
"Point C is point A shifted 50%\nin the direction of point B",
|
|
|
|
"center text-sm"
|
2022-09-29 16:15:17 +02:00
|
|
|
)
|
2022-09-29 16:50:42 +02:00
|
|
|
.attr("data-text-lineheight", 6)
|
2022-12-30 07:47:29 -08:00
|
|
|
|
2022-09-29 16:15:17 +02:00
|
|
|
paths.direction = new Path()
|
|
|
|
.move(points.A)
|
|
|
|
.line(points.B)
|
2022-09-29 16:50:42 +02:00
|
|
|
.setClass("note dashed")
|
2022-12-30 07:47:29 -08:00
|
|
|
|
2022-09-29 16:15:17 +02:00
|
|
|
macro("ld", {
|
|
|
|
from: points.C,
|
|
|
|
to: points.A,
|
2025-05-19 17:20:45 -07:00
|
|
|
d: -10,
|
|
|
|
id: 'macro1',
|
|
|
|
force: true,
|
2022-09-29 16:50:42 +02:00
|
|
|
})
|
2022-12-30 07:47:29 -08:00
|
|
|
|
2022-09-29 16:15:17 +02:00
|
|
|
macro("ld", {
|
|
|
|
from: points.B,
|
|
|
|
to: points.A,
|
2025-05-19 17:20:45 -07:00
|
|
|
d: 20,
|
|
|
|
id: 'macro2',
|
|
|
|
force: true,
|
2022-09-29 16:50:42 +02:00
|
|
|
})
|
2022-09-29 16:15:17 +02:00
|
|
|
|
|
|
|
return part
|
|
|
|
}
|
2021-08-25 16:09:31 +02:00
|
|
|
```
|
2022-09-29 16:15:17 +02:00
|
|
|
</Example>
|
|
|
|
|
|
|
|
|
|
|
|
## Notes
|
|
|
|
|
|
|
|
If you need to move a point by a specific distance instead of a percentage, use
|
|
|
|
[`Point.shiftTowards()`](/reference/api/point/shifttowards/) or
|
|
|
|
[`Point.shiftOutwards()`](/reference/api/point/shiftoutwards/) instead.
|