svg 矩阵转换

https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/matrix

https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/transform

这个方法,应用到多边形,理论上也是可行的吧


/*
在平面内,已知一个矩形的四个角坐标,将矩形绕中心点转动一个角度,求旋转后的角坐标.
也就是已知半径,求每个点旋转后的坐标. 把旋转前和旋转后的点加上中心点看成一个等腰三角形就好解决了,不用扇形公式,而是用三角形公式. 假设矩形的左上角为(left, top),右下角为(right, bottom),
则矩形上任意点(x0, y0)绕其中心(xcenter,ycenter)逆时针旋转angle角度后,新的坐标位置(x′, y′)的计算公式为: xcenter = (right - left + 1) / 2 + left;
ycenter = (bottom - top + 1) / 2 + top; x′ = (x0 - xcenter) cosθ - (y0 - ycenter) sinθ + xcenter;
y′ = (x0 - xcenter) sinθ + (y0 - ycenter) cosθ + ycenter; */
// θ 弧度/角度

https://www.cnblogs.com/zhoug2020/p/5797070.html

https://repl.it/@xgqfrms/svg-matrix-transform

//  θ  arc/ rad / angle

const svgMatrixConvert = (polygon,  angle = 0) => {
const poly = document.querySelector(`[id="${polygon}"]`);
// const {
// x,
// y,
// width,
// height,
// } = poly.getBBox();
// let cx = x + .5 * width
// let cy = y + .5 * height;
const {
x,
y,
width,
height,
// top,
// bottom,
left,
right,
} = poly.getBoundingClientRect();
console.log(`testing`);
const cx = (right - left + 1) / 2 + left;
const cy = (bottom - top + 1) / 2 + top;
// const px = (x0 - xcenter) cosθ - (y0 - ycenter) sinθ + xcenter;
// const py = (x0 - xcenter) sinθ + (y0 - ycenter) cosθ + ycenter;
// polygon points
const points = [];
[...poly.points].forEach(point => {
// SVGPoint
// points.push(point.x + x, point.y + y);
const {
x,
y,
} = point;
// const px = (x - cx) * cosθ - (y - cy) * sinθ + cx;
// const py = (x - cx) * sinθ + (y - cy) * cosθ + cy;
const px = (x - cx) * Math.cos(angle) - (y - cy) * Math.sin(angle) + cx;
const py = (x - cx) * Math.sin(angle) + (y - cy) * Math.cos(angle) + cy;
points.push(px, py);
});
poly.setAttribute(`points`, points.join(` `));
return ;
};

设置旋转的 origin,为 polygon 的中心

默认 SVG, 左上角 0,0


// 设置旋转的 origin,为 polygon 的中心
// 偏移量
getCenter = () => {
// let [top, left, right, bottom] = [];
let [top, left, right, bottom] = ["", "", "", ""];
[...this.poly.points].forEach(({x, y}, i) => {
if (i === 0) {
top = y;
bottom = y;
left = x;
right = x;
} else {
top = Math.min(top, y);
bottom = Math.max(bottom, y);
left = Math.min(left, x);
right = Math.max(right, x);
}
});
return [(left + right) / 2, (top + bottom) / 2];
}

matrix

http://cn.voidcc.com/question/p-fbljwwvs-zm.html

https://blog.csdn.net/atgwwx/article/details/8305842

svg to Map

https://www.codenong.com/38155854/

等比例缩

https://www.zhangxinxu.com/wordpress/2015/10/understand-svg-transform/

svg 矩阵转换的更多相关文章

  1. C 语言实例 - 矩阵转换

    C 语言实例 - 矩阵转换 C 语言实例 C 语言实例 矩阵转换. 实例 #include <stdio.h> int main() { ][], transpose[][], r, c, ...

  2. 数组/矩阵转换成Image类

    Python下将数组/矩阵转换成Image类 原创 2017年04月21日 19:21:27 标签: python / 图像处理 3596 先说明一下为什么要将数组转换成Image类.我处理的图像是F ...

  3. OpenGL 坐标与矩阵转换

    1. OpenGL 渲染管线 OpenGL渲染管线分为两大部分,模型观测变换(ModelView Transformation)和投影变换(Projection Transformation).做个比 ...

  4. 字体图标-把SVG图标转换成所需要的字体图标

    小科普: 想必小伙伴们多少都了解或使用过字体图标,总体来说优点多于缺点,优点如下图: 任意缩放,图标不会失真: 可以改变图标颜色: 可以设置图标阴影: 可以设置透明效果: 主流浏览器都支持: 可以快速 ...

  5. POJ 3268 Silver Cow Party 最短路径+矩阵转换

    Silver Cow Party Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) T ...

  6. bytearray与矩阵转换对应关系

    import numpy as npimport osa=bytearray(os.urandom(27))# for i in range(21):# print(a[i])a=np.array(a ...

  7. 获取Canvas当前坐标系矩阵

    前言 在我的另一篇博文 Canvas坐标系转换 中,我们知道了所有的平移缩放旋转操作都会影响到画布坐标系.那在我们对画布进行了一系列操作之后,怎么再知道当前矩阵数据状态呢. 具体代码 首先请看下面的一 ...

  8. SVG 参考手册

    1. SVG元素模块 Animation.Module animate animateColor animateTransform animateMotion set mpath 剪裁模块 clipP ...

  9. 8个实用的SVG工具,20 个有用的 SVG 工具,五款超实用的开源SVG工具

    8个实用的SVG工具 [导读] 你还在为没有好用的SVG工具而发愁吗?开发人员的福音来啦!小编为大家收集罗列了8款实用的SVG工具,让我们一起来看看吧! SVG可缩放矢量图形(Scalable Vec ...

随机推荐

  1. 页面渲染html的过程

    浏览器渲染页面的一般过程: 1.浏览器解析html源码,然后创建一个 DOM树.并行请求 css/image/js在DOM树中,每一个HTML标签都有一个对应的节点,并且每一个文本也都会有一个对应的文 ...

  2. null调整为not null default xxx,不得不注意的坑

    最近碰到一个case,值得分享一下. 现象 一个DDL,将列的属性从null调整为not null default xxx, alter table slowtech.t1 modify name v ...

  3. 小麦苗数据库巡检脚本,支持Oracle、MySQL、SQL Server和PG等数据库

    目录 一.巡检脚本简介 二.巡检脚本特点 三.巡检结果展示 1.Oracle数据库 2.MySQL数据库 3.SQL Server数据库 4.PG数据库 5.OS信息 四.脚本运行方式 1.Oracl ...

  4. 算法总结篇---AC自动机

    目录 写在前面 算法流程 引例: 概述: Trie树的构建(第一步) 失配指针(第二步) 构建失配指针 字典树和字典图 多模式匹配 例题 写在前面 鸣谢: OiWiki 「笔记」AC 自动机---Lu ...

  5. Flink 在又拍云日志批处理中的实践

    日前,由又拍云举办的大数据与 AI 技术实践|Open Talk 杭州站沙龙在杭州西溪科创园顺利举办.本次活动邀请了有赞.个推.方得智能.又拍云等公司核心技术开发者,现场分享各自领域的大数据技术经验和 ...

  6. 如何用RabbitMQ实现延迟队列

    前言 在 jdk 的 juc 工具包中,提供了一种延迟队列 DelayQueue.延迟队列用处非常广泛,比如我们最常见的场景就是在网购或者外卖平台中发起一个订单,如果不付款,一般 15 分钟后就会被关 ...

  7. CSAPP_BombLab实验报告

    Lab_2实验报告 目录 Lab_2实验报告 屏幕截图 考察内容 各题答案 bomb1 bomb2 bomb3 bomb4 bomb5 bomb6 secret_phase 解题思路 bomb1 bo ...

  8. Codeforces Round #604 (Div. 2) C. Beautiful Regional Contest(贪心)

    题目链接:https://codeforces.com/contest/1265/problem/C 题意 从大到小给出 $n$ 只队伍的过题数,要颁发 $g$ 枚金牌,$s$ 枚银牌,$b$ 枚铜牌 ...

  9. Codeforces Round #644 (Div. 3)

    比赛链接:https://codeforces.com/contest/1360 A - Minimal Square 题意 计算能包含两个 $a \times b$ 矩形的最小正方形的面积. 题解 ...

  10. 2020杭电多校 10C / HDU 6879 - Mine Sweeper (构造)

    HDU 6879 - Mine Sweeper 题意 定义<扫雷>游戏的地图中每个空白格子的值为其周围八个格子内地雷的数量(即游戏内临近地雷数量的提示) 则一张地图的值\(S\)为所有空白 ...