Computing approximated intersection volume between two heightmaps - graphics

The heightmap is a structured grid of points (see picture).
We can easily compute the length of the vertical segments that represent the difference between the two heightmaps.
The question is: how could I compute the approximate intersection volume between the two?

Assume you have 2 height maps h1(x,y) and h2(x,y).
To calculate volume between:
Calculate relative height map h = h2-h1.
Set h=0 if h<0, or make h=abs(h), depends on purpose.
Integrate h(x,y) by dxdy over the region of interest.

Related

Build a geographical map from triangle points based on distance

I have 5 {x,y} points randomly placed on a grid
Each of the points do not know the {x,y} coordinates of the other points
Each of the points do know the distance of each of the other points from their {x,y} position
Each of the points exchanges this distance information with every other point
So every point knows every distance of every other point
Using this distance information every point can calculate (by finding the angles) triangles for every other point using itself as a reference point
Example, point 1 can calculate the following triangles:
1-2-3,
1-2-4,
1-2-5,
1-3-4,
1-3-5,
1-4-5,
and using the distance data recieved from the other points it can also calculate
2-3-4,
2-3-5,
2-4-5,
3-4-5
I would like to build a map of the location of every other point relative to a single point
How should I go about doing this? I am asuming it would be some kind of triangulation algorithm but these mainly seem to compute the location of a point from three other points, not the other way around where the other points {x,y} coordinates are discovered based on only the distance information.
I have tried plotting the two possible triangles for every 3 triangle points and then rotating them on a fixed known point to try and align them, but I think this avenue will end up with too many possibilities and errors
Ultimately I would like every point to end up with {x,y} coordinates of every other point relative to itself
You know the distance from one point to every other, dij. Thus, point 2 lies in a circumference of center point 1 and radius = d12. Point 3 lies in a circumference of center point 1 and R=d13 and it also lies in another circumference of center point 2 and R=d23.
See this picture:
I've set point 2 in X-axis for simplicity.
As you see, point 3 is on the intersection of two cicrcumferences centered at P1 and P2. There is a second intersection, P3a. Let's choose the one that is upwards and continue.
For P4 we can use three circumferences, centered at P1, P2 and P3. Again we get two solutions.
The same process can be done with the rest of points. For Pn you have n-1 circumferences.
I'm sure you can find the maths for circle-circle intersection.
Some remarks must be observed:
1) The construction is simpler if you first sort the points by distance to P1.
2) Not all distances generate a solution. For example, increase d13 an there's no intersection between the two circumferences for P3. Or increase d14 and now the three circumferences don't intersect in just the two expected points 4 and 4a.
3) This fact can be overworked by considering the average of intersections and the distance from each solution to this average. You can set a tolerance in these distances and tell if the average is a solution or else some dij is wrong. Since two solutions are possible, you must consider two averages.
4) The two possible triangulations are symmetric, over X-axis in the case I've drawn.
The real solution is obtained by a rotation around P1. To calculate the angle of rotation you need the {x,y} coordinates of another point.

Cartesian to Latitude/Longitude

I have a 3D model of a 10km x 10km topographic map which I've imported from sketch-up , the model is just a bunch of X,Y,Z points (where X+ is the north and Z+ is straight up, perpendicular to the ground)
I know the Latitude Longitude values of the (0,0,0) point. So given a X,Y,Z point how do I get its Latitude Longitude values?
I need to be pretty accurate so you can't assume the earth is a perfect sphere (you can however assume it's an ellipsoid)
For best accuracy you need to know what map projection the map was drawn in. You should be able to find that out from the map. For example in the UK the Ordnance Survey maps use the OSGB36 datum, and the projection is Transverse mercator. The projection tells you how to convert geographic (lat,long for the datum ellipsoid) coordinates to map coordinates (easting and northing) and how to do the reverse calculation, which is pretty much what you want.
If you don't know the projection, the next best thing would be if you could find out -- again from the map, they are often written on it -- the scale-factor and convergence of the projection at some points on the map. The point is that there is usually a slowly spatially varying difference between map north (the direction the north axis points in) and true north (the direction of the north pole from a point, the direction of the latitude axis) and there is always a slowly spatiallty varying scale factor, the ratio of a distance in map coordinates and the true distance. Note that this not the same thing as the scale of the printed map (an inch to a mile or whatever), it is a property of the projection.
Over a 10km square, it would be reasonably accurate to treat both the scale and convergence as constants. Then given an x,y point you compute the map bearing from 0,0 using
b = atan2(x,y)
and convert this to a true bearing by subtracting the convergence.
You also compute the map distance by
r = hypot(x,y)*S
where S is the scale of the map, e.g. if your a change of 1 in x coordinates represents a distance of 100m, S is 100
and convert r to a true distance by dividing by the scale-factor.
Finally you want to compute the lat,long a given distance and bearing from a given point (the lat,long of 0,0). An accurate way to do this is to use Vincenty's formulae.
One thing to note here is that the scale and convergence, if quoted on the map will be relative to the ellipoid used in construction of the map, so you will be computing lat,long coordinates for that ellipsoid.

Finding closest point to a set of circles

My requirement is to find the point closest to three circles. So lets say the three circles are C1, C2, C3. I want to find the point in the space such that the SUM of its distance from C1, C2 and C3 is MINIMUM.
The distance of a given point from a circle is the distance of the given point from the point that lies on the circle and is intersection of the circle with the line joining the given point with the center of the circle.
Is there a simple logic of find such a point?
Unless one of the distances will be zero, the circle radii are irrelevant: the sum of the distances to the circles will be the sum of the distances to the centers minus the sum of the radii. So in effect you are asking for the geometric median of the circle centers. You might want to iteratively compute an approximation. Or you make use of the fact that you have three circles, in which case the median is the Fermat point of the triangle formed by their centers.
If the point constructed as above lies within one of the circles, then you can move towards that circle while decreasing the sum. So you'd have to consider all the points on that given circle, which you can express as a one-parameter family. You could then compute the distance as a function of that parameter, and the derivative of the resulting formula, and setting that equal to zero will give the optimal solution for this case.

Drawing a circular, minor arc given the centre point and two other points

Does anyone know how to draw a circular, minor arc given the centre point and two other points that lie on the circle?
I want to draw the pixels directly to the screen, and preferably, not have to calculate the angles.
I am using SDL and C, but may be OK studying code given that uses a different language.
Thanks.
All points on a circle are equal distance to the centre.
Given you know two points on the circle you can calculate this distance.
Assuming you have cartesian coordinates, for every x or y value between the known points calculate the other value so that the point is equal distance to the centre and plot these points.
I think this is conceptually the easiest way, though not the most efficient.

Summed area table vs Mipmap

Summed area table is a pre-filtering technique to avoid aliasing in texture map. I would like to know how it works and what are the advantages and disadvantages over Mipmap. Thanks
A summed area table replaces the X*Y texture, T, with an X*Y set of values, S, where entry x,y in S is the sum of all pixels of T contained in the axis-aligned rectangle from [0,0] to [x, y] inclusive.
Given that you want to compute the average of an arbitrary axis-aligned rectangle of pixels of T, you just need to sample the corner locations in S and do some trivial additions and subtractions. (Hmm. It seems that wikipedia sums (pun intended) this up quite succinctly)
The advantages of the SAT is that it will quickly give you the correct results for any arbitrary axis-aligned rectangle (rather than being limited to power-of-2 squares as in MIP mapping) but
You won't get automatic hardware support as you do with MIP maps
the SAT can be huge because, assuming you start summing from the top left texel, the bottom right needs to be able to equal the sum of all the texels. For a 1K*1K texture, you'd need 11 extra bits of precision per channel!

Resources