how to find the min and max of x,y and Z in a 3D convex hull? - computational-geometry

I have a point cloud (P) with 100 points in 3D space. I want to know more about its corresponding convex-hull. My question is how to calculate the minimum and maximum of x,y,z in the P's convex hull?
Maybe the question can be asked in this form:
I was wondering if the points with minimum and maximum x,y and z coordination among of P points are placed on the boundary of P's convex hull?
for example s1 (x1,x2,x3) while x1 is the minimum x between P points, or S2 (x2,y2,z2) while y2 is the maximum y between P points... Now, my questions are:
are s1 and s2 placed on the boundary of P's convex hull?
is x1 the minimum x of the P's convex hull as well? (or y2 the maximum y of the P's convex hull?)
In fact, are xmin,xmax; ymin, ymax; zmin and zmax among of the P points are xmin,xmax; ymin, ymax; zmin and zmax of the P's convex hull too? and if no, how can I compute these 6 items for the P's convex hull?

Related

Find min distance coordinate in 2D space from list coordinates

What is the best and faster way to resolve this problem?
Have a list of coordinates x,y => (x1,y1),(x..,y..),(xn,yn) ; x, y > 0 (intergers)
Find in all 2D space the coordinate (a,b) with the min sum manhattan distance from all point.
a, b can be different from (xn,yn).
Find median point A using only X-coordinates.
Find median point B using only Y-coordinates.
Point with components (A.X, B.Y) is what you need.
Example for 7 points:
point C is median by X - it goes 4-th in order of X-coordinates
point D is median by Y - it goes 4-th in order of Y-coordinates
min dist coordinate is (5,3) (marked by cross)

Distance between point and polygon

Task
Calculate the distance d in meters between a query-point q and a polygon P.
The query-point q is defined as tuple (latitudeq, longitudeq), the polygon P as ordered list of tuples [(latitude1, longitude1), ..., (latituden, longituden)].
Problem
I can't handle latitude and longitude as if they were x- and y-coordinates of a plane as this leads to huge errors if the polygon is not small and not near (0, 0).
Tools
I know how to calculate the distance between two points given each points latitude and longitude. I do also know how to calculate the distance between a point and a great circle. But for this task I'd need to know how to calculate the distance dist(q, 1—2) between a point q and and part of a great-circle 1—2. The distance of q would be simply min(dist(q, a—b)) ∀ a—b in P.
Question
Can you provide me a formula how to calculate the distance between a query-point q defined by a tuple (latitudeq, longitudeq) and a great-circle-arc defined by pair of latitude-longitude-tuples [(latitude1, longitude1),(latitude2, longitude2)]?
Example
If you had code to compute the distance between one point x and a geodesic line
segment s, you could repeat this for each edge of your geodesic polygon.
Let s=(a,b). s is an arc of a great circle. Rotate the sphere so that
s lies on the equator, and x follows along with the sphere rotation.
Then the latitude of x essentially tells you the distance to s: It is either
the distance from x to a, or x to b, or, if x lies in the sector above/below s, it is a simple factor (2 π r) times the latitude.

Intersect quadrilateral with axis-aligned rectangle?

How can one efficiently test if an axis-aligned rectangle R
intersects a nice quadrilateral Q?
Nice means: Q is convex (not a chevron) and non-selfintersecting (not a bowtie, not degenerate).
Just 2D.
Just yes/no. I don't need the actual region of intersection.
Edit: Q and R may be open or closed, whatever's convenient.
Obviously one could test, for each edge of Q, whether it intersects R.
That reduces the problem to
How to test if a line segment intersects an axis-aligned rectange in 2D?.
But just like R's axis-alignedness is exploited by Liang-Barsky
to be faster than Cohen-Sutherland,
Q's properties might be exploited to get something faster than running Liang-Barsky multiple times.
Thus, the polygon-rectangle intersection algorithms
Sutherland–Hodgman, Vatti, and Greiner-Hormann, all of which let Q be nonconvex, are unlikely to be optimal.
Area of rectangle-rectangle intersection looks promising, even though it doesn't exploit R's axis-alignedness.
Be careful not to neglect the case where Q entirely covers R, or vice versa, as the edge test then would give a false negative.
One approach, conceptually:
Regard R as the intersection of two axis-aligned infinite bands, a vertical band [x0,x1] and a horizontal band [y0,y1].
Let xmin and xmax represent the extent of the intersection of Q with the horizontal band [y0,y1]; if [xmin,xmax] ∩ [x0,x1] is non-empty, then Q intersects R.
In terms of implementation:
Initialise xmin := +inf; xmax := -inf
For each edge pq of Q, p=(px,py) q=(qx,qy), with py ≥ qy:
a. If qy > y1 or y0 > py, ignore this edge, and examine the next one.
b. If py > y1, let (x,y1) be the intersection of pq with the horizontal line y = y1; otherwise let x be px.
c. Update xmin = min(xmin,x); xmax = max(xmax,x).
d. If y0 > qy, let (x,y0) be the intersection of pq with the horizontal line y = y0; otherwise let x be qx.
e. Update xmin = min(xmin,x); xmax = max(xmax,x).
Q intersects R if xmin < x1 and xmax > x0.
1) Construct Q's axis-aligned bounding box. Test that it does not intersect R.
2) For every edge E of Q, test that all four vertices of R lie on the outer side of E's supporting line. (Use the implicit equation of the edge, A.x + B.y + c <> 0.)
If and only if either of these tests succeeds, there is no intersection.

Fastest way of calculating the projection of a polygon onto a line

Recently I have started doing some research on the SAT (Separating Axis Theorem) for collision detection in a game I am making. I understand how the algorithm works and why it works, what I'm puzzled about is how it expects one to be able to so easily calculate the projection of the shape onto different axes.
I assume the projection of a polygon onto a vector is represented by line segment from point A to point B, so my best guess to find points A and B would be to find the angle of the line being projected onto and calculate the min and max x-values of the coordinates when the shape is rotated to the angle of the projection (i.e. such that it is parallel to the x-axis and the min and max values are simply the min and max values along the x-axis). But to do this for every projection would be a costly operation. Do any of you guys know a better solution, or could at least point me to a paper or document where a better solution is described?
Simple way to calculate the projection of the polygon on line is to calculate projection of all vertex onto the line and get the coordinates with min-max values like you suggested but you dont need to rotate the polygon to do so.
Here is algorithm to find projection of point on line :-
line : y = mx + c
point : (x1,y1)
projection is intersection of line perpendicular to given line and passing through (x1,y1)
perdenicular line :- y-y1 = -1/m(x-x1) slope of perpendicular line is -1/m
y = -1/m(x-x1) + y1
To find point of intersection solve the equation simultaneously :-
y = mx + c , y = -1/m(x-x1) + y1
mx + c = -1/m(x-x1) + y1
m^2*x + mc = x1-x + my1
(m^2+1)x = x1 + my1 - mc
x = (x1-my1 - mc)/(m^2+1)
y = mx + c = m(x1-my1-mc)/(m^2+1) + c
Time complexity : For each vertex it takes O(1) time so it is O(V) where V is no of vertex in the polygon
If your polygon is not convex, compute its convex hull first.
Given a convex polygon with n vertices, you can find its rotated minimum and maximum x-coordinate in n log n by binary search. You can always test whether a vertex is a minimum or a maximum by rotating an comparing it and the two adjacent vertices. Depending on the results of the comparison, you know whether to jump clockwise or counterclockwise. Jump by k vertices, each time decreasing k by half (at the start k=n/2).
This may or may not bring real speed improvement. If your typical polygon has a dozen or so vertices, it may make little sense to use binary search.

total area of intersecting rectangles

What is an algorithm for determining the total area of two rectangles that are intersecting and may be rotated off the coordinate axes?
Here's roughly what you need to do, expressed as generally as possible, but covering all possibilities:
Work out the class of intersection. I.e. How many edges does the intersection area have? It could be anything from 0 to 8.
Find all vertices of the intersection. This will be all intersections between the edges of the rectangles, and associated corners of the rectangles themselves. Working this bit out is the most complex/tedious.
Work out the area of the intersection, by dividing it up into triangles if necessary.
Here's all the ways the rectangles can intersect:
Update
I've had some thoughts, and the best way to categorize the intersection is to trace round the perimeter of each rectangle and count the number of times each edge intersects another edge. You'll get a vector, e.g. for a six sided intersection area: {1,1,1,1},{0,1,1,1}, and for 8: {2,2,2,2},{2,2,2,2}. The two special cases you'll need to check for are when one rectangle completely encloses the other and when the edges are in line. You'll need to do careful checks, but this would be the starting point for a function to categorize the intersection.
Area(R1 union R2) = Area(R1) + Area(R2) - Area(R1 intersection R2), so you can calculate the area of the intersection to have the area of the union.
Intersections of two rectangles (or two convex polygons) are simple:
They are convex polygons
Their points are characterized as follows: intersection points of any pair of edges, and points of one rectangle which are inside the other.
So it goes like this:
L is an initially empty linked list
R1 has edges e1, e2, e3, e4, R2 has edges f1, f2, f3, f4. Compute intersection points of ei and fj, for all i,j=1,2,3,4. Add them to list L.
For each vertex v of R1, if v is inside R2, add it to L.
For each vertex w of R2, if w is inside R1, add it to L.
The convex hull of points in L is your intersection. As every point in L is on the boundary of the intersection, you can triangulate it and compute its area. Easy:
L = [x0, x1, ... ]
Sort points in L according to the angle of (xi - x0) with respect to an horizontal line passing through x0
First triangle is x0, x1, x2
Second triangle is x0, x2, x3
nth triangle is x0, x(n+1), x(n+2)
The area of a triangle is given by Heron formula:
a, b, c are edge lengths
s = 0.5 * (a + b + c)
area = sqrt(s * (s - a) * (s - b) * (s - c))
but beware of computing s - a, s - b and s - c independantly since you can encounter roundoff error (what if c ~ a and b << a for instance ?)
Ok, you have 3 possibilities:
1. Rectangles don't intersect
2. One rectangle is completely contained within the other (or they coincide)
3. The result of intersection is some convex polygon. You compute the area of a polygon by breaking it into triangles (by drawing segments from the first vertex to every other except for adjacent once). The you sum up the areas. You can use Herodot's theorem to calcaulate triangle's area and that's where midlle school geometry comes in.

Resources