I have a point p, and 2 line segments in a 2D plane. Point p is a location of view from where camera is looking towards the line segments. I want to check if line segment 1 is partially or fully hidden behind the line 2, when looking from the point P.
I think the question is whether the second line is "masked" by the first line.
Let say you camera point is C, and your segments are A1,A2 and B1,B2.
I would compute the cross products CA1xCB1 and CA2xCB2. The sign gives you if the point if the B1 point is on the left or the right of the CA1 line. It depends on how your triangles CA1A2 and CB1B2 are oriented (they must be oriented the same, they are many ways to do that).
You can then use the sign to know if you are in the following cases:
CA1xCB1 is negative or CA2xCB2 is positive, then partially visible
the opposite, then hidden.
You can also compute CA1xCB2 and CA2xCB1 to have fined grained cases.
slurdge's answer is a good start, but it's a bit more complicated than that.
If line segment 2 is closer to C than line segment 1, it could still be visible, e.g.
A1-------A2
B1-B2
C
Here B1 and B2 are "within" the A1A2 sector, but are not hidden.
The hardest one to work out is if B1 is 'between' A1 and A2, but closer to the camera, while B2 is 'not between' A1 and A2, but further from the camera:
B2
A1-----A2
B1
C
B1B2 could clip the edge of the line segment, thus rendering a small portion of B1B2 hidden (or maybe not!). I think you would have to find the intersection of A1A2 and B1B2 to check whether this actually happens.
Related
Issue:
Ran into an interesting problem at work today. I am trying to build a multi path planner algorithm with some interesting rules. I wanted to get the communities thoughts on approaches while I work on whatever I try first. Hoping this is a solved problem already and I just don't know the search terms.
Rules:
There are Nr red start points, there are Nb blue start points. You must draw one path for each start point.
Each path should only intersect once for each combination, for instance path red_1 may only intersect path blue_1 at a single point.
Paths of the same color need to maintain D(istance) from each other and by extension may not intersect. Paths must be contagious to start.
Paths have width 0 < W < 1/3 D.
Paths may not exit the region of interest.
The region is an arbitrary polygon, it may be convex or concave.
Start positions should be predefined by may be placed anywhere within the area of interest or on its edges.
Goal:
Paths should cover as much of the area of interest as possible.
A first pass:
Draw red lines vertically
If red line too close to another on right, move left
If red line too close to another on left, move right
Remove one line from any pair of red lines too close
Draw blue lines horizontally
If blue line too close to another below, move up
If blue line too close to another above, move down
Remove one line from any pair of blue lines too close
Example of random starts in square region
Complete C++ code for this application at https://github.com/JamesBremner/aris2
I have added convex polygon regions of interest, here is an example for a triangular region
looking to see if someone can suggest a site or excel method to find the distance of multiple long,lat coordinates from a one point
example: I have a starting point and 7 other coordinates, is there a way to find how far away (in KM/MI) each point is from the starting point?
Starting loction : 33.17261,-117.14571
list of coordinates
32.75827,-117.17577
32.76079,-117.18589
32.76444,-117.20174
32.59815,-117.01685
32.66387,-117.05577
32.59811,-117.01681
32.66381,-117.05571
lets assume the column they are stored in is column A starting in row 2 (assuming you have a header row). The first thing you are going to want to do is split them into their own columns so you can work with the numbers. There are a couple of ways to do this. The simplest is using the built in feature Text-to-Columns located on the Data ribbon.
Have the whole column selected when you start the process and on the first page, select Delimited.
On the second step choose "," as a delimeter and then press finish. You do not need the third step.
once that is done your data should now be sitting in two columns.
I will place the point you are referring to in C2 and D2, you can use text to columns for this part too or just type it in.
So base on information on another site (assuming its correct), take the earth as a sphere with radius, 6371 km. Place this value in E2.
Next convert your list into X and Y values using the following equations:
F2
=$E$2*COS(RADIANS($B2))*COS(RADIANS($A2))
G2
=$E$2*SIN(RADIANS($B2))*SIN(RADIANS($A2))
note that the degrees were converted to radians for use in excels trig functions
Repeat the process for you starting point coordinates and place the formulas in H2 and I2.
H2
=$E$2*COS(RADIANS($D2))*COS(RADIANS($C2))
I2
=$E$2*SIN(RADIANS($D2))*SIN(RADIANS($C2))
Finally in J2 use the following formula:
=SQRT((F2-$H$2)^2+(G2-$I$2)^2)
Copy the formulas in F2, G2, and J2 down as for as your source list goes. The values in J represent the distance between the X Y points. It does not the curvature of the earth though. Apparently there are many different models to predict this. You need one that works for your area if you want something more refined.
For geodesic grade accuracy (fraction of a mm) you can use my Excel add-in available on GitHub: https://github.com/tdjastrzebski/Vincenty-Excel, in particular VincentyInvDistance() function. The solution implements Vincenty's formulae,
Otherwise use Haversine formula but it does not provide geodesic grade results.
The topic is not that trivial, see Geodesics on an ellipsoid for more details.
I have a data set that has height values every so often, like topography data in a straight line with GPS coordinates. I used the GPS coordinates and trigonometry to make a cumulative distance column. However, the distance between points varies. Sometimes its 10 cm sometimes its 13, sometimes its 40.
I would like to take the average height every 0.5 meters, but sometimes the distance column doesnt even land on a multiple of 0.5! This would mean my output column would be significantly shorter than my raw data column.
I think my main problem is I do not know what this process is called in order to Google it. Another problem is that the distances are irregular as mentioned above. Things I think may have something to do with it:
averageif?
binning? I do not want a histrogram though, just the data.
Thanks for the help and if you do not know the answer but at least know what I should be writing in the search bars that would be helpful as well. Thanks!
Perhaps this will work for you. I made up a series of distance vs height measurements and determined that a third order polynomial curve fit pretty well. (A different curve might best fit your real data, so you would have to alter the formula accordingly). I then used that formula to derive a set of new heights for the desired ditances at, in my example five unit differences.
The formula under Extrapolated heights is an ARRAY formula entered into all the cells at once. You select D2:D12, enter the formula in D2 and, hold down CTRL-SHIFT while hitting ENTER. If you did this correctly, you will have the same formula in each cell surrounded by curly braces {...}
Then you can decide how you want to "Average" the heights.
I have xy grid, where points have whole-numbered, positive coordinates. These points are "neighbours" if both their x and y coordinates differ by less than 2 - they are simply next to each other.
In this grid, I have found path that encloses some area. Every point in the path is neighbour to the previous point and the next point, so it is sorted like you walked around the enclosed area. It is also shortest path around that enclosed area, so there are no steps back and forth. The enclosed area does not need to be convex, so when you connect two random points on the path with one line, that line can lie completely out of that area.
The problem is, I need to find at least one point in enclosed area, that is neighbour to any point in enclosing path.
It might sound easy, but I have not found solid algorithm to determine it.
* I'm sorry, I did not explain that well enough. There are no "empty parts" in enclosed area. If there are three points in enclosed area, the path around is the smallest path that captures those three points. In this picture, red path is shortest, black is too long and I never need to detect those.
Observations to check that I understand the question:
It's possible that there are no such interior points.
Given that consecutive path point are neighbors, the connection
angles will be at multiples of 45°.
The basic idea is to walk the path and keep track of interior and exterior neighbors.
To determine which side is the interior, walk the path and keep track of the cumulative turn angle. The final amount will be 360° or -360° which will indicate the interior is on the left or the right, depending on which way you defined positive and negative angles.
During that first pass, also collect a hash set of the points on the path, onPathPoints.
Initialize two other hash sets to empty: exteriorPoints and possibleInteriorPoints.
Walk the path and for each point:
a. categorize the 8 neighbors as on-path, interior-side or exterior-side based on the relative positions of the previous and next points on the path.
b. for each point in onPathPoints, ignore it.
c. for any point on the interior side and distance 1 away, return that point as the result.
d. for each points on the interior side with distance > 1 (diagonal neighbor), add it to possibleInteriorPoints.
e. for each point on the exterior side and distance 1 away, add it to exteriorPoints.
At the end of the walk, remove from possibleInteriorPoints any point in exteriorPoints (set subtraction). Return any point remaining in possibleInteriorPoints as an interior point.
Otherwise, there are no interior points.
The possibleInteriorPoints represent diagonally neighboring points that are in the interior unless the path loops back between the original point and it (in which case it will be an exterior point to the new path part.
For example in the image below, when visiting (2,2) and going toward (3,3) the interior is on the right. (3,1) is a possible interior point, but later in the walk while visiting (4,1), (3,1) is noted to be an exterior point and so would get removed from possibleInteriorPoints.
Technically, in this example the algorithm would have stopped when visiting (4,3) and noting (4,2) as an interior point at distance 1.
In an infinite 2D space there are a set of lines, each line having a start and end point, and a time of creation: Line(p0, p1, t).
I want to find the lines that should be rendered in a top-down view of this 2D space (higher values of t show up closer to the viewport, not that it should be relevant.)
The intuitive answer is "check if either point is within the viewport coordinates," but this falls down when the points are further apart than the viewport area covers.
The other idea I had was using something like geohash, this would limit precision i.e. maximum zoom level of the viewport. The idea is enumerating the hashes of the cells intersected and storing them. This way querying is a matter of asking the right question.
Are there any ideal solutions? Has this been solved before?
I think you need to check two conditions: one that the rectangle of viewport overlaps the rectangle with corners (p0,p1) and the second that some corners of viewport rectangle are on the different sides of the whole line which contains line segment (p0,p1).
The task of finding rectangle overlap can be solved very effectively for very large number of rectangles using R-trees (http://en.wikipedia.org/wiki/R-tree).
The second task can be reduced to checking signs of the cross product of (p1-p0) x (corner_coordinate-p0)
(all three quantities taken as 3-d vectors with third coordinate equal to zero, the result will be vector along the perpendicular direction). There should be corners with the opposite sign of this cross product.