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. JasperReports 取消自动分页/忽略分页

    因为需要将合同比价单由PDF文档形式改为HTML页面方式,虽然转换文档类型了,但是发现HTML页面中间到了一定行数就出现了空行把Detail给隔开了.之前总想着怎样消除中间空行,以为是报表top页面边 ...

  2. 基于粒子群算法的分组背包MATLAB实现

    抽空看了一段时间的粒子群算法,这里仅针对其应用于动态规划中的背包问题的情况做下总结归纳,其他应用可以之后想到了再添加. 一:分组背包问题简介 假设有3个组,每组有2个物品,每种物品有3种属性,价值.体 ...

  3. 在plsql/developer的命令窗口执行sql脚本

    在plsql/developer的命令窗口执行sql脚本的命令是@+路径. 命令窗口,如下: 1.在指定位置创建.sql文件 2-1.输入@,点击回车,选择.sql文件 2-2.或者@加路径

  4. jQuery——样式与动画

    通过jQuery,不仅能够轻松地为页面操作添加简单的视觉效果,甚至能创建更精致的动画. ###修改内联CSS jQuery提供了.css()方法. 这个方法集getter(获取方法)和setter(设 ...

  5. HarmonyOS三方件开发指南(8)——RoundedImage

    [小年答谢,新春送礼]免费抽取1000元京东卡+更多新春好礼~查看详情>>> 目录: 1. RoundedImage组件功能介绍 2. RoundedImage使用方法 3. Rou ...

  6. 在线工具生成接入信息mqtt.fx快速接入阿里云

    在线工具生成接入信息mqtt.fx快速接入阿里云 在使用阿里云获取的三元组信息进行接入的时候,往往需要加密生成接入信息之后才能进行接入,因此我根据阿里云提供的加密工具实现了一个阿里云物联网平台mqtt ...

  7. 秒啊,速来get这9个jupyter实用技巧

    1 简介 jupyter notebook与jupyter lab作为广受欢迎的ide,尤其适合开展数据分析相关工作,而掌握它们相关的一些实用技巧,势必会大大提升日常工作效率.而今天我就来给大家介绍9 ...

  8. charles(1)解决charles抓包乱码问题

    前言 当使用Charles抓包时,发现数据都是乱码,这时需要安装证书 解决办法 1.点击charles窗口,点击左上角Help-> SSL Proxying -> Install Char ...

  9. Educational Codeforces Round 91 (Rated for Div. 2) D. Berserk And Fireball

    题目链接:https://codeforces.com/contest/1380/problem/D 题意 给出一个大小为 $n$ 的排列 $a$ 和一个序列 $b$,有两种操作: 花费 $x$ 消除 ...

  10. codeforces 630K Indivisibility (容斥原理)

    IT City company developing computer games decided to upgrade its way to reward its employees. Now it ...