Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8693575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:34:30+00:00 2026-06-13T00:34:30+00:00

How is it possible to distort paths in SVG in browser so that they

  • 0

How is it possible to distort paths in SVG in browser so that they are distorted to certain perspective using possibly javascript or css? The perspective distort can be made easily in Photoshop, Illustrator etc, but how about browsers?

This is source path:

enter image description here

And this is the path after transformation:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:34:31+00:00Added an answer on June 13, 2026 at 12:34 am

    This is my drag distort proposal (share you knowledge, Q&A-style).

    Live example is in http://jsfiddle.net/xjHUk/278/ and the main code is this:
    (only output window: http://jsfiddle.net/xjHUk/279/embedded/result/)

    function transferPoint (xI, yI, source, destination)
    {
        var ADDING = 0.001; // to avoid dividing by zero
    
        var xA = source[0].x;
        var yA = source[0].y;
    
        var xC = source[2].x;
        var yC = source[2].y;
        
        var xAu = destination[0].x;
        var yAu = destination[0].y;
    
        var xBu = destination[1].x;
        var yBu = destination[1].y;
    
        var xCu = destination[2].x;
        var yCu = destination[2].y;
    
        var xDu = destination[3].x;
        var yDu = destination[3].y;
    
        // Calcultations
        // if points are the same, have to add a ADDING to avoid dividing by zero
        if (xBu==xCu) xCu+=ADDING;
        if (xAu==xDu) xDu+=ADDING;
        if (xAu==xBu) xBu+=ADDING;
        if (xDu==xCu) xCu+=ADDING;
        var kBC = (yBu-yCu)/(xBu-xCu);
        var kAD = (yAu-yDu)/(xAu-xDu);
        var kAB = (yAu-yBu)/(xAu-xBu);
        var kDC = (yDu-yCu)/(xDu-xCu);
    
        if (kBC==kAD) kAD+=ADDING;
        var xE = (kBC*xBu - kAD*xAu + yAu - yBu) / (kBC-kAD);
        var yE = kBC*(xE - xBu) + yBu;
    
        if (kAB==kDC) kDC+=ADDING;
        var xF = (kAB*xBu - kDC*xCu + yCu - yBu) / (kAB-kDC);
        var yF = kAB*(xF - xBu) + yBu;
    
        if (xE==xF) xF+=ADDING;
        var kEF = (yE-yF) / (xE-xF);
    
        if (kEF==kAB) kAB+=ADDING;
        var xG = (kEF*xDu - kAB*xAu + yAu - yDu) / (kEF-kAB);
        var yG = kEF*(xG - xDu) + yDu;
    
        if (kEF==kBC) kBC+=ADDING;
        var xH = (kEF*xDu - kBC*xBu + yBu - yDu) / (kEF-kBC);
        var yH = kEF*(xH - xDu) + yDu;
    
        var rG = (yC-yI)/(yC-yA);
        var rH = (xI-xA)/(xC-xA);
    
        var xJ = (xG-xDu)*rG + xDu;
        var yJ = (yG-yDu)*rG + yDu;
    
        var xK = (xH-xDu)*rH + xDu;
        var yK = (yH-yDu)*rH + yDu;
    
        if (xF==xJ) xJ+=ADDING;
        if (xE==xK) xK+=ADDING;
        var kJF = (yF-yJ) / (xF-xJ); //23
        var kKE = (yE-yK) / (xE-xK); //12
    
        var xKE;
        if (kJF==kKE) kKE+=ADDING;
        var xIu = (kJF*xF - kKE*xE + yE - yF) / (kJF-kKE);
        var yIu = kJF * (xIu - xJ) + yJ;
    
        var b={x:xIu,y:yIu}; 
        b.x=Math.round(b.x);
        b.y=Math.round(b.y);
        return b;
    }
    
    

    The result is distorted correctly to perspective (two vanishing point one). The principle of two point perspective calculation is here. The script can handle SVG path data if it meets the following requirements:

    • All coordinates are absolute (which means uppercase letters). See this.
    • Arc ("A") is not used
    • V and H are normalized to L

    Arcs can be normalized, but I have not found any crossbrowser way yet. V and H to L is easy task, you have to get the last used x or y coordinate and add the missing one after L.

    The same script can handle also curves in path (curves are from Times). The following is exactly same code but the path attribute ("d") is different:

    http://jsfiddle.net/xjHUk/277/ function dummy(a) {return a;}
    (This code has no check for invalid positions, like the above).

    Paths of above examples are got from SVG versions of Arial and Times. Please note that fonts uses Cartesian coordinate system, in which y-coordinate increases when going upwards. Otherwise SVG uses Polar coordinate system, which is used in bitmap images and css. This means that when using paths from SVG fonts in above code, the path have to be flipped vertically and scaled to desired font-size. TTF fonts (and their SVG counterparts) have usually em size 2048, so the bounding box of glyph is without scaling 2048 px, which usually is too much when SVG glyph path is converted to SVG path.

    But if you want to distort other SVG paths, then flipping and scaling in unnecessary.

    This is fairly long code (much because of drag functionality), but I think that the same effect can be achieved also some css-3D-transform-way, but not luck in such implementation yet…

    For comparison an example of non-perspective distort (SVG’s main competitor SWF):
    http://www.rubenswieringa.com/code/as3/flex/DistortImage/

    And for additional comparison an example of VALID perspective calculation:
    http://zehfernando.com/f/TriangleTest.swf

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Can’t create handler inside thread that has not called Looper.prepare() inside AsyncTask
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: How can I convert a list<> to a multi-dimensional array? I want
Possible Duplicate: How can I understand nested ?: operators in PHP? Why does this:
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: JavaScript: why does parseInt(1/0, 19) return 18? Why does parseInt(1/0, 19) evaluate
Possible Duplicate: Realloc is not resizing array of pointers Can anyone tell me where
Possible Duplicate: How to convert text to unicode code point like \u0054\u0068\u0069\u0073 using php?
Possible Duplicate: Can a Bash script tell what directory it's stored in? Is there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.