I am not quite sure about barycentric coords but I need to use it to do a transformation of coordinates from one local system into the global system using python script. I have this dataset in this format:
pixIndex X Y R G B
1 0 0 227 227 227
2 1 0 237 237 237
3 2 0 0 0 0
4 3 0 232 232 232
5 4 0 233 233 233
... ... ... ... ... ... ...
I have these 3 coordinates from the global coordinate system : {103.890991,1.369125} , {103.8892,1.368017}, (103.8903,1.367166) and in the middle of these 3 points is {103.890221,1.367944}
And these are the equivalent coordinates in the local coordinate system: {207.0,489.0} , {500.0,58.0} , {84.0.17.0} and in the middle of these 3 points is {197.0,262.0}
The barycentric coords can be found with this code but it is not in python:
Vector Triangle::getBarycentricCoordinatesAt( const Vector & P ) const
{
Vector bary ;
// The area of a triangle is
real areaABC = DOT( normal, CROSS( (b - a), (c - a) ) ) ;
real areaPBC = DOT( normal, CROSS( (b - P), (c - P) ) ) ;
real areaPCA = DOT( normal, CROSS( (c - P), (a - P) ) ) ;
bary.x = areaPBC / areaABC ; // alpha
bary.y = areaPCA / areaABC ; // beta
bary.z = 1.0f - bary.x - bary.y ; // gamma
return bary ;
}
Could someone tell me how to python equivalent would look for this snippet and how to use the barycentric ratios to convert my current dataset [local coordinate system to global coordinate system]
I suppose that the formula would be something like this
P=uA+vB+wC.
when I have obtained the ratios represented by bary from the above snippet code for both the local and global coordinate systems. [source: https://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-rendering-a-triangle/barycentric-coordinates#:~:text=To%20compute%20the%20position%20of,(barycentric%20coordinates%20are%20normalized).]
The end result would ideally look something like this
pixIndex X Y R G B T_X T_Y
1 0 0 227 227 227 100.0 1.5
2 1 0 237 237 237 90.0 1.6
3 2 0 0 0 0 110.0 1.5
4 3 0 232 232 232 112.0 1.7
As I am not very familiar with python, could someone show me how I should go about with this conversion from local to global coord system using the reference points I have provided in python?
Any help is much appreciated :)