score:2

You need to split your array into rows and cols and then find intersection for each point. A very basic algorithm for point intersection looks like this:

```
function calculateIntersectionPoint(line1StartX, line1StartY, line1EndX, line1EndY, line2StartX, line2StartY, line2EndX, line2EndY) {
// if the lines intersect, the result contains the x and y of the intersection (treating the lines as infinite) and booleans for whether line segment 1 or line segment 2 contain the point
var denominator, a, b, numerator1, numerator2, result = {
x: null,
y: null,
onLine1: false,
onLine2: false
};
denominator = ((line2EndY - line2StartY) * (line1EndX - line1StartX)) - ((line2EndX - line2StartX) * (line1EndY - line1StartY));
if (denominator == 0) {
return result;
}
a = line1StartY - line2StartY;
b = line1StartX - line2StartX;
numerator1 = ((line2EndX - line2StartX) * a) - ((line2EndY - line2StartY) * b);
numerator2 = ((line1EndX - line1StartX) * a) - ((line1EndY - line1StartY) * b);
a = numerator1 / denominator;
b = numerator2 / denominator;
// if we cast these lines infinitely in both directions, they intersect here:
result.x = line1StartX + (a * (line1EndX - line1StartX));
result.y = line1StartY + (a * (line1EndY - line1StartY));
/*
// it is worth noting that this should be the same as:
x = line2StartX + (b * (line2EndX - line2StartX));
y = line2StartX + (b * (line2EndY - line2StartY));
*/
// if line1 is a segment and line2 is infinite, they intersect if:
if (a > 0 && a < 1) {
result.onLine1 = true;
}
// if line2 is a segment and line1 is infinite, they intersect if:
if (b > 0 && b < 1) {
result.onLine2 = true;
}
// if line1 and line2 are segments, they intersect if both of the above are true
return result;
};
```

A working demo can be found at https://jsfiddle.net/8gguunnq/1/

where on intersection point a circle has been drawn. If you want to omit boundary condition then change the loop restricting as https://jsfiddle.net/8gguunnq/2/

Source: stackoverflow.com

#### Related Query

- How to point intersection of lines in svg and d3.js?
- How to set intersection point of x and y axis
- How do I save/export an SVG file after creating an SVG with D3.js (IE, safari and chrome)?
- D3 how to change the width and length of SVG
- D3, SVG and textPath: How to move the text down?
- How to output SVG in a Jupyter notebook using jsdom, D3 and IJavascript
- How can I copy the content of my SVG and append it to another SVG frame?
- How to maintain the SVG marker width and height ?
- How can I get the natural width and height of an svg image element?
- How do I create a minimap of an SVG using D3 v5 and show the current viewport dimensions?
- get point coordination using path.getPointAtLength after rotation in d3 and svg
- How to drag and drop a group of rectangles in svg in d3.js?
- How do you translate HTML elements along with SVG elements when zooming and panning with D3
- How can I use SVG translate to center a d3.js projection to given latitude and longitude values?
- How to select and deselect a svg line and change its color on selection and deselection using d3.js and javascript , jquery?
- How to position svg circles on a line and curve it?
- How to draw single Pixel lines with d3.js / SVG
- How to get the width and height of an image? ( getBBox() size of SVG return 0 )
- D3js SVG open lines display a fill artifact, how to fix it?
- How to reset svg scaling and fit to screen for random but large maps/datasets with different orientations
- svg rendering order of lines and shapes when using d3
- On a Google maps overlay, how do I create lines between svg elements in D3
- How to properly assign separate colors to different lines and line series in D3 Dimple?
- How to create SVG with grid lines using D3JS
- How to remove double grid lines and force y to the origin
- How to init d3 svg element from embeded extern svg-file and manipulate it
- How to render svg in backend and save to local using in node js using d3?
- How can I scale my map to fit my svg size with d3 and geojson path data
- How can you draw a collection of lines and points based on categorical data in D3?
- d3 v4: How to make a path being curved when only start and end point are known?

#### More Query from same tag

- D3.js rotate shape without rotating text inside
- dc scatter plot binding onClick event
- D3 how to change the width and length of SVG
- d3 update number - count up/down instead of replacing number immediately
- Convert a transition line chart to D3 v4
- How to make upper part of bars rounded?
- D3 How to style keys using their nested values
- D3 V4 - Canvas Transitions: d3.timer duration
- Does D3.js conicConformal projection support the same clipping/trimming options as Matlab?
- D3 donut chart function only works the first time it's called
- How to set color of node based on data value in D3JS
- Svg semantic zoom not working on SVG in HTML
- D3.js .selectAll not working
- D3.js hexbin hexagonal color picker
- Use D3 to generate designed organic shapes like this dynamically?
- Align points in centre of bars (DC.JS composite chart)
- I have a set of string data that I want plot in desired partitions with the string neatly near the plotted circles
- How do I "register" a dragged group to specific coordinates with d3?
- Printing x number of elements per line with javascript and d3.js
- How should I remove nodes in d3-force?
- Round x axis of a time scale to nearest half hour
- How to use mouse click and drag to zoom in D3
- Extend data to extent of graph
- Multiple instances of d3 force layout on the same page
- How to reformat axis labels?
- Assign d3.js Axis a Background Color and Change Layer Ordering
- How to add day numbers to D3 calendar heatmap?
- d3 exit selection comes up empty even with unique id value
- Count number of tick marks in D3.js
- How to control the order of the layers on a map in d3js