JSXGraph logo
JSXGraph
JSXGraph share

Share

Rectangles
QR code
<iframe 
    src="https://jsxgraph.org/share/iframe/rectangles" 
    style="border: 1px solid black; overflow: hidden; width: 550px; aspect-ratio: 55 / 65;" 
    name="JSXGraph example: Rectangles" 
    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>
<div id="board-1-wrapper" class="jxgbox-wrapper " style="width: 100%; ">
   <div id="board-1" 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 BOARDID0 = 'board-0';
    const BOARDID1 = 'board-1';
    const BOARDID = BOARDID0;

    var square1 = function() {
        var board1 = JXG.JSXGraph.initBoard(BOARDID0, { boundingbox: [-5, 5, 5, -5], grid: true, keepaspectratio: true });
        var p1 = board1.create('point', [-2, -2]),
            p2 = board1.create('point', [3, 3]),
            p3 = board1.create('point', [function() { return p1.X() }, function() {
                return p2
                    .Y()
            }], { color: 'blue' }),
            p4 = board1.create('point', [function() { return p2.X() }, function() {
                return p1
                    .Y()
            }], { color: 'blue' }),
            rect = board1.create('polygon', [p1, p3, p2, p4], { hasInnerPoints: true });
    
        p3.isDraggable = true;
        p4.isDraggable = true;
    }
    
    square1();
    
    var square2 = function() {
        var board2 = JXG.JSXGraph.initBoard(BOARDID1, { boundingbox: [-5, 5, 5, -5], grid: true, keepaspectratio: true });
        var p1 = board2.create('point', [-2, -2]),
            p2 = board2.create('point', [3, 3]),
            pm = board2.create('midpoint', [p1, p2], { visible: false }),
            circ = board2.create('circle', [pm, p1], { visible: false }),
            p3 = board2.create('glider', [-2, 3, circ], { color: 'green' }),
            t = board2.create('transform', [Math.PI, pm], { type: 'rotate' }),
            p4 = board2.create('point', [p3, t], { color: 'blue' }),
            rect = board2.create('polygon', [p1, p3, p2, p4], { hasInnerPoints: false });
    }
    
    square2();
 </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 BOARDID0 = 'your_div_id_0'; // Insert your 1st board id here!
const BOARDID1 = 'your_div_id_1'; // Insert your 2nd board id here!

var square1 = function() {
    var board1 = JXG.JSXGraph.initBoard(BOARDID0, { boundingbox: [-5, 5, 5, -5], grid: true, keepaspectratio: true });
    var p1 = board1.create('point', [-2, -2]),
        p2 = board1.create('point', [3, 3]),
        p3 = board1.create('point', [function() { return p1.X() }, function() {
            return p2
                .Y()
        }], { color: 'blue' }),
        p4 = board1.create('point', [function() { return p2.X() }, function() {
            return p1
                .Y()
        }], { color: 'blue' }),
        rect = board1.create('polygon', [p1, p3, p2, p4], { hasInnerPoints: true });

    p3.isDraggable = true;
    p4.isDraggable = true;
}

square1();

var square2 = function() {
    var board2 = JXG.JSXGraph.initBoard(BOARDID1, { boundingbox: [-5, 5, 5, -5], grid: true, keepaspectratio: true });
    var p1 = board2.create('point', [-2, -2]),
        p2 = board2.create('point', [3, 3]),
        pm = board2.create('midpoint', [p1, p2], { visible: false }),
        circ = board2.create('circle', [pm, p1], { visible: false }),
        p3 = board2.create('glider', [-2, 3, circ], { color: 'green' }),
        t = board2.create('transform', [Math.PI, pm], { type: 'rotate' }),
        p4 = board2.create('point', [p3, t], { color: 'blue' }),
        rect = board2.create('polygon', [p1, p3, p2, p4], { hasInnerPoints: false });
}

square2();
<jsxgraph width="100%, 100%" aspect-ratio="1 / 1, 1 / 1" numberOfBoards="2" title="Rectangles" 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.
   */
   
   var square1 = function() {
       var board1 = JXG.JSXGraph.initBoard(BOARDID0, { boundingbox: [-5, 5, 5, -5], grid: true, keepaspectratio: true });
       var p1 = board1.create('point', [-2, -2]),
           p2 = board1.create('point', [3, 3]),
           p3 = board1.create('point', [function() { return p1.X() }, function() {
               return p2
                   .Y()
           }], { color: 'blue' }),
           p4 = board1.create('point', [function() { return p2.X() }, function() {
               return p1
                   .Y()
           }], { color: 'blue' }),
           rect = board1.create('polygon', [p1, p3, p2, p4], { hasInnerPoints: true });
   
       p3.isDraggable = true;
       p4.isDraggable = true;
   }
   
   square1();
   
   var square2 = function() {
       var board2 = JXG.JSXGraph.initBoard(BOARDID1, { boundingbox: [-5, 5, 5, -5], grid: true, keepaspectratio: true });
       var p1 = board2.create('point', [-2, -2]),
           p2 = board2.create('point', [3, 3]),
           pm = board2.create('midpoint', [p1, p2], { visible: false }),
           circ = board2.create('circle', [pm, p1], { visible: false }),
           p3 = board2.create('glider', [-2, 3, circ], { color: 'green' }),
           t = board2.create('transform', [Math.PI, pm], { type: 'rotate' }),
           p4 = board2.create('point', [p3, t], { color: 'blue' }),
           rect = board2.create('polygon', [p1, p3, p2, p4], { hasInnerPoints: false });
   }
   
   square2();
</jsxgraph>

Rectangles

This example shows two interactive rectangles. The first updates as two corner points are dragged, the second uses a glider on a hidden circle and a rotation around the midpoint to form the square dynamically. Both demonstrate real-time polygon updates. **AI generated desctiption**
// Define the ids of your boards in BOARDID0, BOARDID1,...

var square1 = function() {
    var board1 = JXG.JSXGraph.initBoard(BOARDID0, { boundingbox: [-5, 5, 5, -5], grid: true, keepaspectratio: true });
    var p1 = board1.create('point', [-2, -2]),
        p2 = board1.create('point', [3, 3]),
        p3 = board1.create('point', [function() { return p1.X() }, function() {
            return p2
                .Y()
        }], { color: 'blue' }),
        p4 = board1.create('point', [function() { return p2.X() }, function() {
            return p1
                .Y()
        }], { color: 'blue' }),
        rect = board1.create('polygon', [p1, p3, p2, p4], { hasInnerPoints: true });

    p3.isDraggable = true;
    p4.isDraggable = true;
}

square1();

var square2 = function() {
    var board2 = JXG.JSXGraph.initBoard(BOARDID1, { boundingbox: [-5, 5, 5, -5], grid: true, keepaspectratio: true });
    var p1 = board2.create('point', [-2, -2]),
        p2 = board2.create('point', [3, 3]),
        pm = board2.create('midpoint', [p1, p2], { visible: false }),
        circ = board2.create('circle', [pm, p1], { visible: false }),
        p3 = board2.create('glider', [-2, 3, circ], { color: 'green' }),
        t = board2.create('transform', [Math.PI, pm], { type: 'rotate' }),
        p4 = board2.create('point', [p3, t], { color: 'blue' }),
        rect = board2.create('polygon', [p1, p3, p2, p4], { hasInnerPoints: false });
}

square2();

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.