create a ploygon counding shape javascript d3












0















I have a series of dots plotted on a chart that looks similar to this:
enter image description here



and I would like to create a bounding polygon around them, like this:
enter image description here



I've found quite a good explanation of how to do this at
http://bl.ocks.org/gka/1552725
Calculate bounding polygon of alpha shape from the Delaunay triangulation but this is using version 3 of d3 and I am using version 4. I have managed to implement some of the example using the v4 but can't work out how to filter the triangles So far I've managed this:
enter image description here



I'd appreciate any help given. My code looks like this:



vertices = vertices.map((d) => {
//console.log(d)
return [xScale(d[0]),yScale(d[1])]
})
let alpha = 30

let dsq = function(a,b) {
var dx = a[0]-b[0], dy = a[1]-b[1];
return dx*dx+dy*dy;
}
let asq = alpha*alpha

vertices = vertices.filter(function(t) {
return dsq(t[0],t[1]) < asq && dsq(t[0],t[2]) < asq && dsq(t[1],t[2]) < asq;
})

let outline = Delaunay.from(vertices)
//let { points, triangles } = outline;

parent.append('path')
.attr('fill', '#FCE6D6')
.attr('opacity',0.5)
.attr('stroke', '#000000')
.attr('d', outline.render());


Changing the final line to:



.attr('d', outline.renderHull());


will give me the convex hull of the shape, but it's the concave hull I'm trying to create. I'm guessing that I filter the vertices before passing them to the outline constant via Delauny.from(vertices). I've tried that using the equations in the v3 example linked above, but that just removes all the vertices.










share|improve this question

























  • play with the alpha parameter, it determines which triangle to remove.

    – rioV8
    Nov 26 '18 at 12:34











  • I tried that, changing it from 0.1 through to 10000 and they still get removed

    – Bob Haslett
    Nov 26 '18 at 12:36











  • what would be the test to remove the triangles? There are numerous concave hulls. Why remove one slidder traingle and not the other?

    – rioV8
    Nov 26 '18 at 12:52











  • I guess that's what Im not fully understanding, I thought just changing the alpha value would have done it, or most of it

    – Bob Haslett
    Nov 26 '18 at 12:59
















0















I have a series of dots plotted on a chart that looks similar to this:
enter image description here



and I would like to create a bounding polygon around them, like this:
enter image description here



I've found quite a good explanation of how to do this at
http://bl.ocks.org/gka/1552725
Calculate bounding polygon of alpha shape from the Delaunay triangulation but this is using version 3 of d3 and I am using version 4. I have managed to implement some of the example using the v4 but can't work out how to filter the triangles So far I've managed this:
enter image description here



I'd appreciate any help given. My code looks like this:



vertices = vertices.map((d) => {
//console.log(d)
return [xScale(d[0]),yScale(d[1])]
})
let alpha = 30

let dsq = function(a,b) {
var dx = a[0]-b[0], dy = a[1]-b[1];
return dx*dx+dy*dy;
}
let asq = alpha*alpha

vertices = vertices.filter(function(t) {
return dsq(t[0],t[1]) < asq && dsq(t[0],t[2]) < asq && dsq(t[1],t[2]) < asq;
})

let outline = Delaunay.from(vertices)
//let { points, triangles } = outline;

parent.append('path')
.attr('fill', '#FCE6D6')
.attr('opacity',0.5)
.attr('stroke', '#000000')
.attr('d', outline.render());


Changing the final line to:



.attr('d', outline.renderHull());


will give me the convex hull of the shape, but it's the concave hull I'm trying to create. I'm guessing that I filter the vertices before passing them to the outline constant via Delauny.from(vertices). I've tried that using the equations in the v3 example linked above, but that just removes all the vertices.










share|improve this question

























  • play with the alpha parameter, it determines which triangle to remove.

    – rioV8
    Nov 26 '18 at 12:34











  • I tried that, changing it from 0.1 through to 10000 and they still get removed

    – Bob Haslett
    Nov 26 '18 at 12:36











  • what would be the test to remove the triangles? There are numerous concave hulls. Why remove one slidder traingle and not the other?

    – rioV8
    Nov 26 '18 at 12:52











  • I guess that's what Im not fully understanding, I thought just changing the alpha value would have done it, or most of it

    – Bob Haslett
    Nov 26 '18 at 12:59














0












0








0








I have a series of dots plotted on a chart that looks similar to this:
enter image description here



and I would like to create a bounding polygon around them, like this:
enter image description here



I've found quite a good explanation of how to do this at
http://bl.ocks.org/gka/1552725
Calculate bounding polygon of alpha shape from the Delaunay triangulation but this is using version 3 of d3 and I am using version 4. I have managed to implement some of the example using the v4 but can't work out how to filter the triangles So far I've managed this:
enter image description here



I'd appreciate any help given. My code looks like this:



vertices = vertices.map((d) => {
//console.log(d)
return [xScale(d[0]),yScale(d[1])]
})
let alpha = 30

let dsq = function(a,b) {
var dx = a[0]-b[0], dy = a[1]-b[1];
return dx*dx+dy*dy;
}
let asq = alpha*alpha

vertices = vertices.filter(function(t) {
return dsq(t[0],t[1]) < asq && dsq(t[0],t[2]) < asq && dsq(t[1],t[2]) < asq;
})

let outline = Delaunay.from(vertices)
//let { points, triangles } = outline;

parent.append('path')
.attr('fill', '#FCE6D6')
.attr('opacity',0.5)
.attr('stroke', '#000000')
.attr('d', outline.render());


Changing the final line to:



.attr('d', outline.renderHull());


will give me the convex hull of the shape, but it's the concave hull I'm trying to create. I'm guessing that I filter the vertices before passing them to the outline constant via Delauny.from(vertices). I've tried that using the equations in the v3 example linked above, but that just removes all the vertices.










share|improve this question
















I have a series of dots plotted on a chart that looks similar to this:
enter image description here



and I would like to create a bounding polygon around them, like this:
enter image description here



I've found quite a good explanation of how to do this at
http://bl.ocks.org/gka/1552725
Calculate bounding polygon of alpha shape from the Delaunay triangulation but this is using version 3 of d3 and I am using version 4. I have managed to implement some of the example using the v4 but can't work out how to filter the triangles So far I've managed this:
enter image description here



I'd appreciate any help given. My code looks like this:



vertices = vertices.map((d) => {
//console.log(d)
return [xScale(d[0]),yScale(d[1])]
})
let alpha = 30

let dsq = function(a,b) {
var dx = a[0]-b[0], dy = a[1]-b[1];
return dx*dx+dy*dy;
}
let asq = alpha*alpha

vertices = vertices.filter(function(t) {
return dsq(t[0],t[1]) < asq && dsq(t[0],t[2]) < asq && dsq(t[1],t[2]) < asq;
})

let outline = Delaunay.from(vertices)
//let { points, triangles } = outline;

parent.append('path')
.attr('fill', '#FCE6D6')
.attr('opacity',0.5)
.attr('stroke', '#000000')
.attr('d', outline.render());


Changing the final line to:



.attr('d', outline.renderHull());


will give me the convex hull of the shape, but it's the concave hull I'm trying to create. I'm guessing that I filter the vertices before passing them to the outline constant via Delauny.from(vertices). I've tried that using the equations in the v3 example linked above, but that just removes all the vertices.







javascript d3.js charts






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 12:42







Bob Haslett

















asked Nov 26 '18 at 10:40









Bob HaslettBob Haslett

511424




511424













  • play with the alpha parameter, it determines which triangle to remove.

    – rioV8
    Nov 26 '18 at 12:34











  • I tried that, changing it from 0.1 through to 10000 and they still get removed

    – Bob Haslett
    Nov 26 '18 at 12:36











  • what would be the test to remove the triangles? There are numerous concave hulls. Why remove one slidder traingle and not the other?

    – rioV8
    Nov 26 '18 at 12:52











  • I guess that's what Im not fully understanding, I thought just changing the alpha value would have done it, or most of it

    – Bob Haslett
    Nov 26 '18 at 12:59



















  • play with the alpha parameter, it determines which triangle to remove.

    – rioV8
    Nov 26 '18 at 12:34











  • I tried that, changing it from 0.1 through to 10000 and they still get removed

    – Bob Haslett
    Nov 26 '18 at 12:36











  • what would be the test to remove the triangles? There are numerous concave hulls. Why remove one slidder traingle and not the other?

    – rioV8
    Nov 26 '18 at 12:52











  • I guess that's what Im not fully understanding, I thought just changing the alpha value would have done it, or most of it

    – Bob Haslett
    Nov 26 '18 at 12:59

















play with the alpha parameter, it determines which triangle to remove.

– rioV8
Nov 26 '18 at 12:34





play with the alpha parameter, it determines which triangle to remove.

– rioV8
Nov 26 '18 at 12:34













I tried that, changing it from 0.1 through to 10000 and they still get removed

– Bob Haslett
Nov 26 '18 at 12:36





I tried that, changing it from 0.1 through to 10000 and they still get removed

– Bob Haslett
Nov 26 '18 at 12:36













what would be the test to remove the triangles? There are numerous concave hulls. Why remove one slidder traingle and not the other?

– rioV8
Nov 26 '18 at 12:52





what would be the test to remove the triangles? There are numerous concave hulls. Why remove one slidder traingle and not the other?

– rioV8
Nov 26 '18 at 12:52













I guess that's what Im not fully understanding, I thought just changing the alpha value would have done it, or most of it

– Bob Haslett
Nov 26 '18 at 12:59





I guess that's what Im not fully understanding, I thought just changing the alpha value would have done it, or most of it

– Bob Haslett
Nov 26 '18 at 12:59












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53479340%2fcreate-a-ploygon-counding-shape-javascript-d3%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53479340%2fcreate-a-ploygon-counding-shape-javascript-d3%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks