Published
Edited
May 2, 2020
2 stars
Also listed in…
Geometry
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
polygon
Insert cell
Insert cell
pCalculated = getInnerCrossingPointCoordinate({c,cr1:intP})
Insert cell
polygon = getSkewedPolygonVertexes (c,intP,cr2)
Insert cell
function getSkewedPolygonVertexes(c, cr1, cr2){
// remove after integration
[c,cr1,cr2].forEach(p=>{p.xPos=p.x;p.yPos=p.y});
const max = 200||this.boundMax;
let vertexes = [c,cr1];
const normalize = (x,y) =>{
if(x==-max) return (+y+max) / (max*2) / 4;
if(y==+max) return (+x+max) / (max*2) / 4 + 0.25;
if(x==+max) return (-y+max) / (max*2) / 4 + 0.50;
if(y==-max) return (-x+max) / (max*2) / 4 + 0.75;
}
const cr1Norm = normalize(cr1.xPos,cr1.yPos);
const cr2Norm = normalize(cr2.xPos,cr2.yPos);
const edgePointExtents = {
'bottom':[{xPos:-max,yPos:-max},{xPos:-max,yPos:+max},{xPos:+max,yPos:+max},{xPos:+max,yPos:-max}],
'left':[{xPos:-max,yPos:+max},{xPos:+max,yPos:+max},{xPos:+max,yPos:-max},{xPos:-max,yPos:-max}],
'top':[{xPos:+max,yPos:+max},{xPos:+max,yPos:-max},{xPos:-max,yPos:-max},{xPos:-max,yPos:+max}],
'right':[{xPos:+max,yPos:-max},{xPos:-max,yPos:-max},{xPos:-max,yPos:+max},{xPos:+max,yPos:+max}]
}
const edge = getCrossingPointEdge(cr1)
const extentPoints = edgePointExtents[edge]
const extentPointNorm = extentPoints.map(p=>normalize(p.xPos,p.yPos));
extentPointNorm.forEach((normP,i)=>{
if(cr1Norm<=normP && normP<=cr2Norm){
vertexes.push(extentPoints[i])
}
if(cr1Norm>cr2Norm){
if(!(cr2Norm<=normP && normP<=cr1Norm)){
vertexes.push(extentPoints[i])
}
}
});
vertexes.push(cr2);

vertexes.forEach(p=>{p.x=p.xPos;p.y=p.yPos});
return vertexes;
return {
vertexes,
extentPointNorm,
cr1Norm,
cr2Norm
};




}
Insert cell
function getCrossingPointEdge(point){
const max = 200;
if(point.yPos == -max) return 'bottom';
if(point.xPos == -max) return 'left';
if(point.yPos == +max) return 'top';
if(point.xPos == +max) return 'right';


}
Insert cell
pCalculated
Insert cell
getPointLineRegression({c,p:intP}).y(-100+innerRectX)
Insert cell
getPointLineRegression({c,p:intP})
Insert cell
-100-innerRectY
Insert cell
100-innerRectY
Insert cell
function getInnerCrossingPointCoordinate({c,cr1}){
const boundXMin = -100+innerRectX;
const boundXMax = 100+innerRectX;
const boundYMin = -100-innerRectY;
const boundYMax = 100-innerRectY;
const regr = getPointLineRegression({c,p:cr1});
if(regr.a == +Infinity) return {x:c.x,y:boundYMin};
if(regr.a == -Infinity) return {x:c.x,y:boundYMax};


let values = [
{name:'left', value:regr.y(boundXMin), point:{x:boundXMin,y:regr.y(boundXMin)}, invalid:c.x<cr1.x, invalidBounds: regr.y(boundXMin) < boundYMin || regr.y(boundXMin) > boundYMax},
{name:'right', value:regr.y(boundXMax), point:{x:boundXMax,y:regr.y(boundXMax)}, invalid:c.x>cr1.x, invalidBounds: regr.y(boundXMax) < boundYMin || regr.y(boundXMax) > boundYMax},
{name:'top', value:regr.x(boundYMax), point:{y:boundYMax,x:regr.x(boundYMax)}, invalid:c.y>cr1.y, invalidBounds: regr.x(boundYMax) < boundXMin || regr.x(boundYMax) > boundXMax},
{name:'bottom', value:regr.x(boundYMin), point:{y:boundYMin,x:regr.x(boundYMin)}, invalid:c.y<cr1.y, invalidBounds: regr.x(boundYMin) < boundXMin || regr.x(boundYMin) > boundXMax},
]
.filter(d=>!d.invalid)
.filter(d=>!d.invalidBounds);


return values[0].point;

}
Insert cell
function getCrossingCoordinate({c,p}){
//return getCrossingPointCC({c,p})
const bound = 200;
const regr = getPointLineRegression({c,p});
if(regr.a == Infinity ) return {x:c.x,y:-bound}
if(regr.a == -Infinity ) return {x:c.x,y:bound}
let values = [
{name:'left', value:regr.y(-bound), point:{x:-bound,y:regr.y(-bound)}, invalid:c.x<p.x},
{name:'right', value:regr.y(bound), point:{x:bound,y:regr.y(bound)}, invalid:c.x>p.x},
{name:'top', value:regr.x(bound), point:{y:bound,x:regr.x(bound)}, invalid:c.y>p.y},
{name:'bottom', value:regr.x(-bound), point:{y:-bound,x:regr.x(-bound)}, invalid:c.y<p.y},
]
.filter(d=>!d.invalid)

const result = values.filter(d=>Math.abs(d.value)<=bound)[0];
return result.point;
}
Insert cell
function getPointLineRegression({c,p}){
// Linear regression is y = ax + b, let's determine a and b based on supplied points
const a = (c.y-p.y)/(c.x-p.x);
const b = c.y-a * c.x;
const result = {
y:(x)=> a * x + b,
x:(y)=> (y-b)/a,
a,
b
}
result.a = a;
result.b = b;
return result;
}
Insert cell
Insert cell
import {slider} from "@jashkenas/inputs"
Insert cell
import {inputsGrid} from "@bumbeishvili/utils"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
scalesY = d3.scaleLinear().domain([0,-400]).range([0,400])
Insert cell
d3 = require('d3')
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more