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 8094255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:44:39+00:00 2026-06-05T20:44:39+00:00

We are developing an drawing application for iOS and android. I am using cubic

  • 0

We are developing an drawing application for iOS and android. I am using cubic quadratic curves to draw smooth curves because cubic Bézier curve is way slow to draw on mobile devices(mostly pads).

Drawing long quadratic curve with lot of points is still slow in pads so I am trying to reduce points I have to plot on canvas to speed up drawing.

I have tried,

  1. Catmull-Rom splines
  2. Ramer-Douglas-Peucker

but they are for cubic curves and not has not working properly for quad-curves.

Is there any algorithm or techniques for quad curves as well? can any other optimization be done to speed up path drawing?

  • 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-05T20:44:41+00:00Added an answer on June 5, 2026 at 8:44 pm

    You could subdivide the spline segment recursively, until they are almost a straight line.

    function Subdivide( C : Curve, maxDepth : int )
    begin
        if maxDepth ≤ 1 or Polyline-Length( C ) ≤ 1px or StraightLineMeasure( C ) < ϵ then
            return List-Single( C )
        end
        C1, C2 ← Split( C )
        return List-Concat( Subdivide( C1, maxDepth – 1 ), Subdivide( C2, maxDepth – 1 ) )
    end

    where
    Polyline-Length calculates the length of the poly-line formed by the control points.
    StraightLineMeasure returns zero for a straight line, and a small number for almost straight lines.
    Split returns two sets of control points, each of which represents half of the original curve.

    B-Splines are easy to subdivide (pdf).


    Screenshot

    (click here for demo)

    Here is an implementation in javascript:

    $(function() {
        var canvas = document.createElement('canvas');
        document.body.appendChild(canvas);
    
        var ctx = canvas.getContext('2d');
        ctx.fillStyle = '#f00';
        ctx.strokeStyle = '#f00';
        ctx.lineWidth = 1;
    
        var segments = BSplineSegment.FromBSpline([
            new Vector(10, 10),
            new Vector(110, 10),
            new Vector(110, 110),
            new Vector(10, 110),
            new Vector(10, 10),
            new Vector(110, 10),
            new Vector(110, 110)
            ]);
    
        for (var i = 0; i < segments.length; i++) {
            var subsegments = segments[i].subdivide(30);
            for (var j = 0; j < subsegments.length; j++) {
                var bss = subsegments[j];
                ctx.fillRect(bss.p1.x, bss.p1.y, 1, 1);
            }
        }
    
        var segment = new BSplineSegment(
            new Vector(110, 10), new Vector(210, 10),
            new Vector(110, 110), new Vector(210, 110));
        subsegments = segment.subdivide(50);
        for (var j = 0; j < subsegments.length; j++) {
            var bss = subsegments[j];
            ctx.fillRect(bss.p1.x, bss.p1.y, 1, 1);
        }
    });
    
    function Vector(x, y) {
        this.x = x;
        this.y = y;
    }
    
    Vector.prototype = {
        lengthSquared: function() {
            return this.x * this.x + this.y * this.y;
        },
        length: function() {
            return Math.sqrt(this.lengthSquared());
        },
        add: function(other) {
            return new Vector(this.x + other.x, this.y + other.y);
        },
        sub: function(other) {
            return new Vector(this.x - other.x, this.y - other.y);
        },
        mul: function(scale) {
            return new Vector(this.x * scale, this.y * scale);
        },
        div: function(scale) {
            return new Vector(this.x / scale, this.y / scale);
        },
        cross: function(other) {
            return this.x * other.y - this.y * other.x;
        },
    };
    
    
    function BSplineSegment(p0, p1, p2, p3) {
        this.p0 = p0;
        this.p1 = p1;
        this.p2 = p2;
        this.p3 = p3;
    };
    
    BSplineSegment.FromBSpline = function(pts) {
        var n = pts.length;
        var segments = [];
        for (var i = 3; i < n; i++) {
            segments.push(new BSplineSegment(pts[i - 3], pts[i - 2], pts[i - 1], pts[i]));
        }
        return segments;
    };
    
    BSplineSegment.prototype = {
        polylineLength: function() {
            return this.p2.sub(this.p1).length();
        },
        straightLineMeasure: function() {
            var det0 = this.p1.cross(this.p2);
            var det1 = det0 + this.p2.cross(this.p0) + this.p0.cross(this.p1);
            var det2 = det0 + this.p2.cross(this.p3) + this.p3.cross(this.p1);
            return (Math.abs(det1) + Math.abs(det2)) / this.p2.sub(this.p1).length();
        },
        split: function() {
            var p0 = this.p0.add(this.p1).mul(0.5);
            var p1 = this.p0.add(this.p1.mul(6)).add(this.p2).mul(0.125);
            var p2 = this.p1.add(this.p2).mul(0.5);
            var p3 = this.p1.add(this.p2.mul(6)).add(this.p3).mul(0.125);
            var p4 = this.p2.add(this.p3).mul(0.5);
            return [new BSplineSegment(p0, p1, p2, p3), new BSplineSegment(p1, p2, p3, p4)];
        },
        subdivide: function(maxLevels) {
            if (maxLevels <= 0 || this.polylineLength() < 1.0 || this.straightLineMeasure() < 1.0) {
                return [this];
            }
            else {
                var children = this.split();
                var left = children[0].subdivide(maxLevels - 1);
                var right = children[1].subdivide(maxLevels - 1);
                return left.concat(right);
            }
        }
    };​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi an developing drawing android application. in that i want to add a sticker(image)
I'm developing a retained mode drawing application in GDI+. The application can draw simple
I'm developing the Android application for drawing. So, I NEED to use MVC pattern
I am developing an application using Processing.js. At each step in the drawing loop
I have been developing the application for drawing, and I have the problem: my
I have been developing the application for drawing and I need to detect double
I have been developing the application for drawing, and there is the code: public
I have been developing the application for drawing and I have some problems: the
I have been developing the application for drawing, and there is the following code
I am developing an iPad application which is basically a big drawing canvas with

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.