i looking way calculate intersection point 2 lines,i have javascript method works fine sample x , y
//start of linear part window.linear = { getslope: function(x1, y1, x2, y2) { if (x1 == x2) return false; return (y1 - y2) / (x1 - x2); }, getyint: function(x1, y1, x2, y2) { if (x1 === x2) return y1 === 0 ? 0 : false; if (y1 === y2) return y1; return y1 - this.getslope(x1, y1, x2, y2) * x1; }, getxint: function(x1, y1, x2, y2) { var slope; if (y1 === y2) return x1 == 0 ? 0 : false; if (x1 === x2) return x1; return (-1 * ((slope = this.getslope(x1, y1, x2, y2)) * x1 - y1)) / slope; }, getint: function(x11, y11, x12, y12, x21, y21, x22, y22) { var slope1, slope2, yint1, yint2, intx, inty; // check if either of points same. if that's our intersection if (x11 == x21 && y11 == y21) return [x11, y11]; if (x12 == x22 && y12 == y22) return [x12, y22]; // slope: (y1 - y1) / (x1 - x2) slope1 = this.getslope(x11, y11, x12, y12); slope2 = this.getslope(x21, y21, x22, y22); // if both lines have same slope, paralell; never touch. if (slope1 === slope2) return false; // y-intersection: y - slope * x yint1 = this.getyint(x11, y11, x12, y12); yint2 = this.getyint(x21, y21, x22, y22); // check see if both lines have same yintcept, , if so, return point if (yint1 === yint2) return yint1 === false ? false : [0, yint1]; // if 1 of lines doesn't have slope: if (slope1 === false) return [y21, slope2 * y21 + yint2]; if (slope2 === false) return [y11, slope1 * y11 + yint1]; //if both lines have slop , y intercept, calulate x-intercept: // (slope1 * x1 + yint1 - yint2) / slope2; intx = (slope1 * x11 + yint1 - yint2) / slope2; // calculate y-intercept, , return array: return [intx, slope1 * intx + yint1]; } } // end of linear
this it..but when add sample point cesium gives wrong answers. think because of radiance , geographic convetations..does 1 has idea how fix it?
this 2 point of sample line
var start=new cesium.cartesian3(0.7007890932991216, -1.3246378751475405, 0) var end=new cesium.cartesian3(0.7007917595851312, -1.3246388181033268, 0)
and line
var st=new cesium.cartesian3(0.7007909619371219, -1.3246425889783457, 0) var en=new cesium.cartesian3(0.7007881826635102, -1.3246415011312433, 0)
this how using it
var e = linear.getint(start.x,start.y,end.x,end.y,st.x,st.y,en.x, en.y)||["n/a","n/a"];
it gives me wrong point...i think must perform convtration because points in radiant..right?can 1 me it?
Comments
Post a Comment