forked from didi/LogicFlow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): node => rotate+正常模式resize(didi#1428)
- Loading branch information
Showing
5 changed files
with
297 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
export interface SimplePoint { | ||
x: number | ||
y: number | ||
} | ||
|
||
/** | ||
* 根据两个点获取中心点坐标 | ||
*/ | ||
export function getNewCenter(startPoint: SimplePoint, endPoint: SimplePoint) { | ||
const { x: x1, y: y1 } = startPoint | ||
const { x: x2, y: y2 } = endPoint | ||
const newCenter = { | ||
x: x1 + (x2 - x1) / 2, | ||
y: y1 + (y2 - y1) / 2, | ||
} | ||
return newCenter | ||
} | ||
|
||
/** | ||
* 旋转矩阵公式,可以获取某一个坐标旋转angle后的坐标 | ||
* @param p 当前坐标 | ||
* @param center 旋转中心 | ||
* @param angle 旋转角度(不是弧度) | ||
*/ | ||
export function calculatePointAfterRotateAngle( | ||
p: SimplePoint, | ||
center: SimplePoint, | ||
angle: number, | ||
) { | ||
const radian = angleToRadian(angle) | ||
const dx = p.x - center.x | ||
const dy = p.y - center.y | ||
const x = dx * Math.cos(radian) - dy * Math.sin(radian) + center.x | ||
const y = dx * Math.sin(radian) + dy * Math.cos(radian) + center.y | ||
return { | ||
x, | ||
y, | ||
} | ||
} | ||
|
||
/** | ||
* 角度转弧度 | ||
* @param angle 角度 | ||
*/ | ||
export function angleToRadian(angle: number) { | ||
return (angle * Math.PI) / 180 | ||
} | ||
|
||
/** | ||
* 弧度转角度 | ||
* @param radian 弧度 | ||
*/ | ||
export function radianToAngle(radian: number) { | ||
return (radian / Math.PI) * 180 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters