Home
Random example
Search
Applications
Chemistry
Economy
Famous theorems
Geography
Physics
Sports
Test
Assessment
Calculus
3D
Applied calculus
Basic calculus
Differential equations
Function plotting
Implicit plotting
Sequences and series
Charts and data
Charts
Statistics
Curves
Interpolation
Intersection, Union, Difference
Lindenmayer Systems
Splines
Geometry
3D
Analytic
Euclidean
Basic constructions
Mappings
Non-Euclidean
Projective
Symmetry
Technical
Accessibility
Animation
Roulettes
Board options
First steps
Images
JSXGraph objects
Arcs and angles
Axes
Circles
Glider
Groups
Lines and arrows
Point
Polygons
Slider
Turtle
Vectors
JessieCode
Texts
Transformations
Video
jsxgraph.org
JSXGraph logo
JSXGraph
JSXGraph share

Share

Shade region bounded by curves
Show plain example
QR code
<iframe 
    src="https://www.jsxgraph.uni-bayreuth.de/share/iframe/shade-region-bounded-by-curves" 
    style="border: 1px solid black; overflow: hidden; width: 550px; aspect-ratio: 55 / 65;" 
    name="JSXGraph example: Shade region bounded by curves" 
    allowfullscreen
></iframe>
This code has to
<div id="board-0-wrapper" class="jxgbox-wrapper " style="width: 100%; ">
   <div id="board-0" class="jxgbox" style="aspect-ratio: 1 / 1; width: 100%;" data-ar="1 / 1"></div>
</div>

<script type = "text/javascript"> 
    /*
    This example is licensed under a 
    Creative Commons Attribution ShareAlike 4.0 International License.
    https://creativecommons.org/licenses/by-sa/4.0/
    
    Please note you have to mention 
    The Center of Mobile Learning with Digital Technology
    in the credits.
    */
    
    const BOARDID = 'board-0';

    const board = JXG.JSXGraph.initBoard(BOARDID, {
        boundingbox: [-1, 2, 2, -1],
        axis: true
    });
    
    // 1.  We need the mutual intersections of the curves.
    // However, only one intersection is not obvious.
    // Numerically compute intersection of the first two curves, 'sqrt(x^2-1)' and '0.707*x'
    var diff = x => Math.sqrt(x * x - 1) - 0.707 * x;
    var x_intersect = JXG.Math.Numerics.root(diff, 1.5);
    
    // 2. Plot curves only up to the mutual intersections
    // We use JessieCode for the function terms
    var curve1 = board.create('functiongraph', ['0', 0, 1]);
    var curve2 = board.create('functiongraph', ['sqrt(x^2-1)', 1, x_intersect]);
    var curve3 = board.create('functiongraph', ['0.707*x', 0, x_intersect]);
    
    // 3. Plot a filled curve which starts at (0,0), contains all points of 'sqrt(x^2-1)'
    // and is closed by adding (0,0) at the end.
    var curve = board.create('curve', [[], []], { strokeWidth: 3, fillColor: 'yellow', fillOpacity: 0.3 });
    curve.updateDataArray = function() {
        // Start with (0, 0)
        this.dataX = [0];
        this.dataY = [0];
    
        // Copy all points from curve2
        this.dataX = this.dataX.concat(curve2.points.map(p => p.usrCoords[1]));
        this.dataY = this.dataY.concat(curve2.points.map(p => p.usrCoords[2]));
    
        // Close the curve by adding (0,0)
        this.dataX.push(0);
        this.dataY.push(0);
    };
    board.update();
 </script> 
/*
This example is licensed under a 
Creative Commons Attribution ShareAlike 4.0 International License.
https://creativecommons.org/licenses/by-sa/4.0/

Please note you have to mention 
The Center of Mobile Learning with Digital Technology
in the credits.
*/

const BOARDID = 'your_div_id'; // Insert your id here!

const board = JXG.JSXGraph.initBoard(BOARDID, {
    boundingbox: [-1, 2, 2, -1],
    axis: true
});

// 1.  We need the mutual intersections of the curves.
// However, only one intersection is not obvious.
// Numerically compute intersection of the first two curves, 'sqrt(x^2-1)' and '0.707*x'
var diff = x => Math.sqrt(x * x - 1) - 0.707 * x;
var x_intersect = JXG.Math.Numerics.root(diff, 1.5);

// 2. Plot curves only up to the mutual intersections
// We use JessieCode for the function terms
var curve1 = board.create('functiongraph', ['0', 0, 1]);
var curve2 = board.create('functiongraph', ['sqrt(x^2-1)', 1, x_intersect]);
var curve3 = board.create('functiongraph', ['0.707*x', 0, x_intersect]);

// 3. Plot a filled curve which starts at (0,0), contains all points of 'sqrt(x^2-1)'
// and is closed by adding (0,0) at the end.
var curve = board.create('curve', [[], []], { strokeWidth: 3, fillColor: 'yellow', fillOpacity: 0.3 });
curve.updateDataArray = function() {
    // Start with (0, 0)
    this.dataX = [0];
    this.dataY = [0];

    // Copy all points from curve2
    this.dataX = this.dataX.concat(curve2.points.map(p => p.usrCoords[1]));
    this.dataY = this.dataY.concat(curve2.points.map(p => p.usrCoords[2]));

    // Close the curve by adding (0,0)
    this.dataX.push(0);
    this.dataY.push(0);
};
board.update();
<jsxgraph width="100%" aspect-ratio="1 / 1" title="Shade region bounded by curves" description="This construction was copied from JSXGraph examples database: BTW HERE SHOULD BE A GENERATED LINKuseGlobalJS="false">
   /*
   This example is licensed under a 
   Creative Commons Attribution ShareAlike 4.0 International License.
   https://creativecommons.org/licenses/by-sa/4.0/
   
   Please note you have to mention 
   The Center of Mobile Learning with Digital Technology
   in the credits.
   */
   
   const board = JXG.JSXGraph.initBoard(BOARDID, {
       boundingbox: [-1, 2, 2, -1],
       axis: true
   });
   
   // 1.  We need the mutual intersections of the curves.
   // However, only one intersection is not obvious.
   // Numerically compute intersection of the first two curves, 'sqrt(x^2-1)' and '0.707*x'
   var diff = x => Math.sqrt(x * x - 1) - 0.707 * x;
   var x_intersect = JXG.Math.Numerics.root(diff, 1.5);
   
   // 2. Plot curves only up to the mutual intersections
   // We use JessieCode for the function terms
   var curve1 = board.create('functiongraph', ['0', 0, 1]);
   var curve2 = board.create('functiongraph', ['sqrt(x^2-1)', 1, x_intersect]);
   var curve3 = board.create('functiongraph', ['0.707*x', 0, x_intersect]);
   
   // 3. Plot a filled curve which starts at (0,0), contains all points of 'sqrt(x^2-1)'
   // and is closed by adding (0,0) at the end.
   var curve = board.create('curve', [[], []], { strokeWidth: 3, fillColor: 'yellow', fillOpacity: 0.3 });
   curve.updateDataArray = function() {
       // Start with (0, 0)
       this.dataX = [0];
       this.dataY = [0];
   
       // Copy all points from curve2
       this.dataX = this.dataX.concat(curve2.points.map(p => p.usrCoords[1]));
       this.dataY = this.dataY.concat(curve2.points.map(p => p.usrCoords[2]));
   
       // Close the curve by adding (0,0)
       this.dataX.push(0);
       this.dataY.push(0);
   };
   board.update();
</jsxgraph>

Shade region bounded by curves

Calculus
Curves
Function plotting
Somewhere in the world wide web the question was asked how to shade the region bounded by the following curves, where $x\ge 0$: $$ \begin{eqnarray*} x & \mapsto & \sqrt{x^2-1} \\ x & \mapsto & 0.707 x \\ x & \mapsto & 0 \\ \end{eqnarray*} $$ Here is a somewhat *hacky* the solution. The steps are: 1. First, we need the mutual intersections of the curves. However, only one intersection is not obvious. Numerically compute intersection of the first two curves, $\sqrt{x^2-1}$ and $0.707x$. 2. Plot curves only up to the mutual intersections. We use JessieCode for the function terms. 3. Plot a filled curve which linearly connects the points $(0,0)$, all points of the curve $\sqrt{x^2-1}$ and finally is closed by adding $(0,0)$ at the end. For other curves, especially, if the curves are closed, it might be easier to use the lement `CurveIntersection`.
// Define the id of your board in BOARDID

const board = JXG.JSXGraph.initBoard(BOARDID, {
    boundingbox: [-1, 2, 2, -1],
    axis: true
});

// 1.  We need the mutual intersections of the curves.
// However, only one intersection is not obvious.
// Numerically compute intersection of the first two curves, 'sqrt(x^2-1)' and '0.707*x'
var diff = x => Math.sqrt(x * x - 1) - 0.707 * x;
var x_intersect = JXG.Math.Numerics.root(diff, 1.5);

// 2. Plot curves only up to the mutual intersections
// We use JessieCode for the function terms
var curve1 = board.create('functiongraph', ['0', 0, 1]);
var curve2 = board.create('functiongraph', ['sqrt(x^2-1)', 1, x_intersect]);
var curve3 = board.create('functiongraph', ['0.707*x', 0, x_intersect]);

// 3. Plot a filled curve which starts at (0,0), contains all points of 'sqrt(x^2-1)'
// and is closed by adding (0,0) at the end.
var curve = board.create('curve', [[], []], { strokeWidth: 3, fillColor: 'yellow', fillOpacity: 0.3 });
curve.updateDataArray = function() {
    // Start with (0, 0)
    this.dataX = [0];
    this.dataY = [0];

    // Copy all points from curve2
    this.dataX = this.dataX.concat(curve2.points.map(p => p.usrCoords[1]));
    this.dataY = this.dataY.concat(curve2.points.map(p => p.usrCoords[2]));

    // Close the curve by adding (0,0)
    this.dataX.push(0);
    this.dataY.push(0);
};
board.update();

license

This example is licensed under a Creative Commons Attribution ShareAlike 4.0 International License.
Please note you have to mention The Center of Mobile Learning with Digital Technology in the credits.