TeaTreeTim said:
I'm not sure the above is correct, or situationally not correct: If you triangulate a point location given 2 known points and their distances, then there are 2 possible answers.
I mean to take 3 points from the curve to make a triangle, not 2 points plus the unknown source point.
If you have a piece wise linear function (like distance to a unknown point), sampled from 3 points, the direction of the gradient points towards the source and there is no uncertainty about two solutions.
But temperature does not diffuse linearly, so that's why making a approximate conversion from temperature to distance before calculating the gradient could improve results, i assume.
Here some example code i'm using to calculate gradient vector for all triangles of a mesh (Division by area seems not necessary if we only care about direction, also note there are multiple ways to calculate gradients from triangles AFAIK, but this worked for me):
static void TriangleGradientFromVertexMap (std::vector<vec> &triangleGradient,
const std::vector<float> &vertexMap, // distance or temperature per vertex
const LinkMesh &mesh)
{
triangleGradient.resize(mesh.mPolys.size());
for (int pI=0; pI<mesh.mPolys.size(); pI++)
{
const LinkMesh::Poly &poly = mesh.mPolys[pI];
vec normal = mesh.mPolyNormals[pI];
vec sum (0);
for (int i=0; i<3; i++)
{
int vI = poly.vertexIndices[i];
int evI0 = poly.vertexIndices[(i+1)%3];
int evI1 = poly.vertexIndices[(i+2)%3];
vec edge = mesh.mVertexPositions[evI1] - mesh.mVertexPositions[evI0];
sum += normal.Cross(edge) * vertexMap[vI];
}
float area = mesh.mPolyArea[pI];
vec gradient = sum / (2*area);
triangleGradient[pI] = gradient;
//RenderArrow (mesh.mPolyCenters[pI], gradient, 0.05f, 1,1,0);
}
}
I want to add taking 3 adjacent points from the curve might be a bad idea. Maybe taking sets of any 3 points where sampled temperature differs a lot would be better.
In 3D, using triangles of course gives gradient aligned to the plane of the triangle, So the ‘hight’ of source from that plane is unknown, which makes solution harder.
If the problem is 3D, i would insert the samples into a 3D voulme, set the samples as fixed boundary and solve for harmonic map to fill the whole volume with data. Then a gradient can be calculated at each cell of the volume which is not limited to planes of triangles.
…no idea how well any of this workes in practice, assuming differnces in temeprature are small and samples are noisy.