Reputation: 397
Hi I have a need to create a Ternary Plot graph from 3 different variables.
http://en.wikipedia.org/wiki/Ternary_plot
I basically need to come up with the x/y coordinates of the point within the triangle, from the ratio of the 3 variables.
Is there any function / algorithm that anyone is using to create this? The language I am using by the way is ActionScript 3
Thanks
Upvotes: 1
Views: 1525
Reputation: 15623
Martin provided the right solution. In AS3, you'd probably want to use the flash.geom.Point
class.
public function calculateCoordinate(a:Number, b:Number, c:Number):Point {
var sum:Number = a + b + c;
a /= sum;
b /= sum;
c /= sum;
return scale(Triangle.Corner1Position, a)
+ scale(Triangle.Corner2Position, b)
+ scale(Triangle.Corner3Position, c);
}
public function scale(p:Point, factor:Number):Point {
return new Point(p.x * factor, p.y * factor);
}
Upvotes: 2
Reputation: 12403
Wikipedia says that a ternary plot is:
a barycentric plot on three variables which sum to a constant
A barycentric plot takes three variables, which sum to 1, as parameters. So first things first divide your three inputs by their sum.
Now that you have three numbers which sum to one, you can plot a barycentric point. To do this simply multiply the position of one of the points on the triangle by the first numbers, multiply the second point on the triangle by the second number, and the third by the third. Then sum then all together, this is the position you should plot on the graph.
public Vector2 CalculateCoordinate(float a, float b, float c)
{
float sum = a + b + c;
a /= sum;
b /= sum;
c /= sum;
return Triangle.Corner1Position * a
+ Triangle.Corner2Position * b
+ Triangle.Corner3Position * c;
}
Upvotes: 2