SYS_Math.translate() method
Translate the polygon
Signature
typescript
function translate(polygon: TSYS_MathPolygonInput, dx: number, dy: number): Array<ISYS_MathPoint>;1
Parameters
Parameter | Type | Description |
|---|---|---|
polygon | Polygon | |
dx | number | X direction offset |
dy | number | Y direction offset |
Returns
Array<ISYS_MathPoint>
Array of discrete points after translation
Example
javascript
// 1. 定义一个器件占位轮廓
const footprint = [{ x: 0, y: 0 }, { x: 100, y: 0 }, { x: 100, y: 80 }, { x: 0, y: 80 }];
// 2. 向右平移 200、向上平移 150(得到排布到新位置的轮廓)
const placed = eda.sys_Math.translate(footprint, 200, 150);
console.log('平移后的顶点:', JSON.stringify(placed));
// 3. 负偏移向左下方平移
const back = eda.sys_Math.translate(placed, -200, -150);
console.log('再平移回原位后的第一个点:', JSON.stringify(back[0]));
// 4. 平移前后形状不变,周长与面积保持一致
console.log('平移前后周长:', eda.sys_Math.calculatePerimeter(footprint), '/', eda.sys_Math.calculatePerimeter(placed));1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13