简体   繁体   中英

Generate point based on intersection of two line beyond canvas limit

I want to generate two dummy point based on intersection of two lines. If the line is intersected beyond the canvas region so it can't be computed. The two dummy point can be predicted as having ay position at 0 or max-Y and intersected with each line.


detail :

Well im having a problem with my program. In order to generate a correct point from a set of one point and two line, I must find if the two line that im having is intersect with each other.

Java.Line2D.intersectsLine() API can simply find this condition but my real problem is that sometimes a line will intersect beyond the canvas boundaries (x<0, y<0, x>maxX, y>maxY ). The line im having is considered infinite, however technical problem limit me to draw my line at y=0 and y=maxY. To fix that, I generate a two dummy point from both line to become a replacement for that point.

http://i.stack.imgur.com/23aSD.jpg

As you can see, in the first image I can easily get F as an answer for my task. However when the intersection point is beyond canvas/panel boundaries I must generate two dummy point as replacement.

There are two set of point that I can get, that is B&E or C&D, the correct answer is of course B&E but i don't know how to get the correct algorithm to solve this. At first Im trying to create a line from A to each respective point in each line and get the biggest one angle as you can see in the picture number 2 as answer, with that I manage to find that the correct answer is the one with the biggest angle. But in every possible random condition the two line positioning cannot be predicted and somehow I'm stumbled at this condition.

A new condition appeared : http://i.stack.imgur.com/tGZy1.jpg

In this condition the two biggest angle is owned by B and D, so it destroy the hypothesis for taking the correct point. So in order to correct this I'm currently brainstorming for this problem. However if there any of you out there can give me some enlightenment, it will be absolutely appreciated. Even a math concept is great, so maybe any of you guys have any idea?

By the way, the point will within the two line and Im checking the line one by one in my algorithm.

Any help is appreciated.

for (int i = 0;i<lineContainer.size()-1;i++){
for (int j = i+1;j<lineContainer.size();j++){

if lineContainer.get(i).intersectsLine(lineContainer.get(j)){
point = getIntersectionPoint(lineContainer.get(i), lineContainer.get(j));
answer.add(point);
}else{
// Based on assumption that line that not paralel will somewhere intersects
Point[] p = new Point[2];
p[0] = lineContainer.get(i).getP1();
p[1] = lineContainer.get(i).getP2();

Line l = new Line(queryPoint, p[0]);
double[] d = new double[2];

d[0] = checkAngle(l, lineContainer.get(i));
l = new Line(queryPoint, p[1]);

d[1] = checkAngle(l, lineContiner.get(i));
if(d[0]>d[1]){
answer.add(p[0]);
}else{
answer.add(p[1]);
}
}
}
}

Solve it this morning, detail in the picture

http://i.stack.imgur.com/zk8MQ.jpg

As you can see in the image, you can generate the replacement point by creating a region from each point, and calculate the inside angle of the region. The correct combination will create the biggest sum of angle. And it will be always > 180 degrees since the sum of all angle inside the region will always result in 360 degrees.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM