Home Web Front-end H5 Tutorial How to implement coordinate system transformation in svg (with code)

How to implement coordinate system transformation in svg (with code)

Aug 02, 2018 pm 02:44 PM
svg

This article introduces to you a summary of various methods of using svg in react (with code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

Cartesian Coordinate System Conversion

If there are other systems transmitting data to SVG, you may have to deal with using Cartesian Coordinates represent vector graphics of data. Point (0, 0) is located in the lower left corner of the canvas, and the y coordinate increases upward. The y-axis is "opposite" to SVG's default convention, so the coordinates need to be recalculated.

The following example:

<svg width="200px" height="200px" viewbox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
 <g transform="translate(0, 100) scale(1, -1)">
    <line x1="0" y1="0" x2="100" y2="0" style="stroke: black" />
    <line x1="0" y1="0" x2="0" y2="100" style="stroke: black" />
    
    <polygin points="40 40, 100 40, 70 70, 40 70" style="fill: grey; stroke: black" />
  </g>
<svg>
Copy after login

SVG Transform

translate(x, y): Follow Move the user coordinate system by the specified x and y values ​​
scale(xFactor, yFactor): Multiply all user coordinate systems using the specified xFactor and yFactor. The scale value can be a decimal or a negative value
scale(factor): Same as scale(xFactor, yFactor)
rotate(angle): Rotate the user coordinates according to the specified angle. The center of rotation is the origin (0, 0). In the default coordinate system, the rotation angle increases clockwise, and the angle of the horizontal line is 0 degrees
rotate(angle, centerX, centerY): Rotate the user coordinates according to the specified angel. The center of rotation is specified by centerX and centerY
skewX(angle): Skew all x coordinates according to the specified angle. Visually, this makes the vertical line appear angled
skewY(angle): Skew all y coordinates according to the specified angle. Visually speaking, this will make the horizontal line appear at an angle

Recommended related articles:

The role of svg path: How to use svg path in web development

Summary of various methods of using svg in react (with code)

The above is the detailed content of How to implement coordinate system transformation in svg (with code). For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Let's talk about how to use SVG to achieve image mosaic effect Let's talk about how to use SVG to achieve image mosaic effect Sep 01, 2022 am 11:05 AM

How to use SVG to achieve image mosaic effect without using Javascript? The following article will give you a detailed understanding, I hope it will be helpful to you!

How to convert svg to jpg format How to convert svg to jpg format Nov 24, 2023 am 09:50 AM

svg can be converted to jpg format by using image processing software, using online conversion tools, and using the Python image processing library. Detailed introduction: 1. Image processing software includes Adobe Illustrator, Inkscape and GIMP; 2. Online conversion tools include CloudConvert, Zamzar, Online Convert, etc.; 3. Python image processing library, etc.

An in-depth analysis of how to use svg icons in vue3+vite An in-depth analysis of how to use svg icons in vue3+vite Apr 28, 2022 am 10:48 AM

svg images are widely used in projects. The following article will introduce how to use svg icons in vue3 + vite. I hope it will be helpful to everyone!

Detailed explanation of using SVG to add logo to favicon Detailed explanation of using SVG to add logo to favicon Sep 07, 2022 am 10:30 AM

How to add logo to favicon using SVG? The following article will introduce to you how to use SVG to generate favicon with logo. I hope it will be helpful to you!

VUE3 introductory tutorial: Use Vue.js plug-in to play with SVG VUE3 introductory tutorial: Use Vue.js plug-in to play with SVG Jun 16, 2023 am 09:48 AM

With the continuous development of modern Web front-end development, more and more technologies are widely used in actual development. Among them, Vue.js is currently one of the most popular JavaScript frameworks. It is based on the MVVM model and provides a rich API and component library, making it easier to develop responsive, reusable, and efficient web applications. The latest version of Vue.js3 has better performance and richer features than the old version, which has attracted widespread attention and research. This article will introduce to you a

How to use svg method in vue3+vite2 How to use svg method in vue3+vite2 May 11, 2023 pm 05:55 PM

1. Install vite-plugin-svg-icons. You also need to install fast-glob related dependencies. Otherwise, when vite runs npmrundev, it will report the Cannotfindmodule'fast-glob' error npmifast-glob@3.x-Dnpmivite-plugin-svg. -icons@2.x-D 2. Create a new component index.vueimport{computed}from'vue';cons under src/components/svgIcon

How to use svg in vue3+vue-cli4 How to use svg in vue3+vue-cli4 May 11, 2023 pm 05:58 PM

1. Install svg-sprite-loadernpminstallsvg-sprite-loader--save-dev 2. Create a new component under src/components/svgIcon index.vueimport{computed}from"@vue/reactivity";exportdefault{name:"baseSvgIcon", props:{iconClass:{type:String},className:{type:String},},setup

Draw SVG files on HTML5 canvas Draw SVG files on HTML5 canvas Sep 15, 2023 pm 03:09 PM

To draw HTMLImageElements on a canvas element, use the drawImage() method. This method defines an Image variable using src="mySVG.svg" and uses drawImage when loading. varmyImg=newImage();myImg.onload=function(){ ctx.drawImage(myImg,0,0);}img.src="http://www.example.com/files/sample.svg";

See all articles