0

I am into a situation where is need to find out of the shape is drawn inside an other shape on canvas.

For Example:

I have a canvas and I draw a random shape by plotting the points on the canvas and apply the color in it.

Secondly, I have to draw an other shape inside the first shape on the same canvas.

Here all I need to know technically if the second shape drawn in completely inside the first shape.

I am using javascript and easelJs.

Edit : Sample code how I plot points

const drawingCanvas = new createjs.Shape();

        drawingCanvas.graphics
            .clear()
            .setStrokeStyle(canvas.height)
            .setStrokeDash([14, 8])
            .beginStroke('white')
            .moveTo(midPt.x,midPt.y)
            .curveTo(
                oldPt.x,
                oldPt.y,
                oldMidPt.x,
                oldMidPt.y
            );


    const mouseX = this.stage.mouseX;
    const mouseY = this.stage.mouseY;
    this.plotPoints.push({ x: mouseX, y: mouseY });

Created oldPt and oldMidPt using createjs.Point

Thanks

Niranth Reddy
  • 493
  • 1
  • 11
  • 27
  • This is mainly about comparing two polygons and as such more a math question than a programming question. The basic idea is to intersect every line of shape A with every line of shape B. If no two lines intersect, and an arbitrary point of the 2nd shape is inside the 1st shape, then the condition is fulfilled. So you need line-vs-line and point-vs-polygon. –  Oct 15 '19 at 10:13
  • Possible duplicate of [Check if polygon is inside a polygon](https://stackoverflow.com/questions/4833802/check-if-polygon-is-inside-a-polygon) –  Oct 15 '19 at 10:13
  • More technically speaking, need to check the array of Image-pixels of 1st shape and 2nd shape. so need javascript logic to know if shape2 is inside shape1 – Niranth Reddy Oct 15 '19 at 10:19
  • So i think not so related to the above mentioned and more of javascript/canvas logic required. – Niranth Reddy Oct 15 '19 at 10:21
  • So we're not talking about Polygons? But pixels? How are you plotting the points? –  Oct 15 '19 at 10:22
  • Updated with sample code on how I plot points – Niranth Reddy Oct 15 '19 at 10:35
  • 1
    So you're drawing quadratic bezier curves? That requires a curve v curve algorithm to check for intersections. Still a math question really. There's no magical shortcut here, I'm afraid. –  Oct 15 '19 at 10:42

0 Answers0