-1

I'm trying to measure in % how much the X and Y coordinates of a point inside an ABC triangle moved from its original place, knowing how much % has the A,B,C points moved.

Example: Knowing that the following points moved from their original position: A.x 30%, A.y 45%, B.x 10%, B.y 20%, C.x 70%, C.Y 60%, find out how much the coordinates X and Y of a point P inside the A,B,C triangle moved.

How can I calculate the offset of any point inside such a triangle?

duffymo
  • 305,152
  • 44
  • 369
  • 561
Antarus
  • 1
  • 1
  • 4

2 Answers2

1

I believe you need the Barycentric coordinates here. Eventually those give you a chance to represent a given point P in the triangle with vertices t1, t2, t3 as P = a * t1 + b * t2 + c * t3. Given this, the new coordinates after translating the triangle into t1', t2', t3' will result into P' = a * t1' + b * t2' + c * t3' i.e. you would just apply the same weights to every corner.

Taken into account you start with cartesian coordinates here are the formulas to do the conversion from cartesian to barycentric i.e. find the a, b, c I mentioned before.

Alexandru Barbarosie
  • 2,952
  • 3
  • 24
  • 46
0

Since you did have the c++, I'll answer the question from a programmer prospective rather than a mathematician so this may not be the best mathematical way to do it. the way i would calculate this is I would first work out the left-most and right-most point of the triangle so this would be the points with the lowest x value and the highest x value then using the following formula we calculate it's percentile position within the triangle.

percentile.x = (rightMostPoint.x - leftMostPoint.x) / (point.x - leftMostPoint.x);

The Y axis is pretty much the same. Please note as well that firstly this function returns a float percentile so 0.5 = 50% and also a values between 0% and 100% don't guarantee that the point is within the triangle.

Now you know the percentile position you can simply calculate the difference in between the before and after percentile position. i.e.

percentileChangeOnX = abs(precentPosBefore.x - precentPosAfter.x);
Kits
  • 118
  • 8