svg 矩阵转换
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 矩阵转换的更多相关文章
- C 语言实例 - 矩阵转换
C 语言实例 - 矩阵转换 C 语言实例 C 语言实例 矩阵转换. 实例 #include <stdio.h> int main() { ][], transpose[][], r, c, ...
- 数组/矩阵转换成Image类
Python下将数组/矩阵转换成Image类 原创 2017年04月21日 19:21:27 标签: python / 图像处理 3596 先说明一下为什么要将数组转换成Image类.我处理的图像是F ...
- OpenGL 坐标与矩阵转换
1. OpenGL 渲染管线 OpenGL渲染管线分为两大部分,模型观测变换(ModelView Transformation)和投影变换(Projection Transformation).做个比 ...
- 字体图标-把SVG图标转换成所需要的字体图标
小科普: 想必小伙伴们多少都了解或使用过字体图标,总体来说优点多于缺点,优点如下图: 任意缩放,图标不会失真: 可以改变图标颜色: 可以设置图标阴影: 可以设置透明效果: 主流浏览器都支持: 可以快速 ...
- POJ 3268 Silver Cow Party 最短路径+矩阵转换
Silver Cow Party Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) T ...
- bytearray与矩阵转换对应关系
import numpy as npimport osa=bytearray(os.urandom(27))# for i in range(21):# print(a[i])a=np.array(a ...
- 获取Canvas当前坐标系矩阵
前言 在我的另一篇博文 Canvas坐标系转换 中,我们知道了所有的平移缩放旋转操作都会影响到画布坐标系.那在我们对画布进行了一系列操作之后,怎么再知道当前矩阵数据状态呢. 具体代码 首先请看下面的一 ...
- SVG 参考手册
1. SVG元素模块 Animation.Module animate animateColor animateTransform animateMotion set mpath 剪裁模块 clipP ...
- 8个实用的SVG工具,20 个有用的 SVG 工具,五款超实用的开源SVG工具
8个实用的SVG工具 [导读] 你还在为没有好用的SVG工具而发愁吗?开发人员的福音来啦!小编为大家收集罗列了8款实用的SVG工具,让我们一起来看看吧! SVG可缩放矢量图形(Scalable Vec ...
随机推荐
- java中List元素移除元素的那些坑
https://blog.csdn.net/javageektech/article/details/96668890 List 的迭代器类 采用倒序移除 jdk1.8的写法 public sta ...
- 命名规范 api-guidelines api规范
https://weui.io weui.css .weui-cell_select-before .weui-cell__bd:after{ display:none; } .weui-cell_s ...
- io流读写操作
/** * * DOC 将F盘下的test.jpg文件,读取后,再存到E盘下面. * * @param args * @throws Exception */ public static void m ...
- java切割~~百万 十万 万 千 百 十 个 角 分
/** * @param value * @return */ @SuppressWarnings("unused") public static void convertLoan ...
- PHP-表单提交(form)
PHP-表单提交 一 form表单 GET 将表单内容附加到URL地址后面,提交的信息长度有限制,不可以超过8192个字节,同时不具有保密性,而且只能传送ASCII字符(一般传送的不保密性数据 ...
- pytest测试框架+jenkins结合pytest+jenkins邮件通知配置
刚刚做完一个项目,由于这是一个方案项目,而不是产品,所以各种准备很不充分,很多公司的能力不能复用,整个团队又都是新员工,而且有部分实习生,匆忙上马,今天对我的自动化框架做一个回溯 自动化测试框架的选择 ...
- python里正则表达式基础及注意事项
感觉正则匹配是一件很酷的事,用得好的话可以极大地提高编程效率.虽然在html中BeautifulSoup更好用一些,但有时候还是需要使用正则匹配.所以就此做一些学习和使用过程中的笔记. python有 ...
- 浅谈Winform控件开发(一):使用GDI+美化基础窗口
写在前面: 本系列随笔将作为我对于winform控件开发的心得总结,方便对一些读者在GDI+.winform等技术方面进行一个入门级的讲解,抛砖引玉. 别问为什么不用WPF,为什么不用QT.问就是懒, ...
- Snapshots常用命令
HBase Snapshots允许你对一个表进行快照(即可用副本),它不会对Region Servers产生很大的影响,它进行复制和 恢复操作的时候不包括数据拷贝.导出快照到另外的集群也不会对Regi ...
- Codeforces Round #655 (Div. 2) C. Omkar and Baseball
题目链接:https://codeforces.com/contest/1372/problem/C 题意 给出一个大小为 $n$ 的排列,每次操作可以选取一个连续子数组任意排列其中的元素,要求每个元 ...