[R] centroid of diamond
Jim Lemon
jim at bitwrit.com.au
Fri Mar 14 06:08:22 CET 2014
On 03/14/2014 06:03 AM, al Vel wrote:
> Hello R users,
> I am trying to make a baricentric diagram like the ternary plot, but with 4
> edges. I want to know how to calculate the centroid of the diamond. The 4
> edges are A, B, C, D. If value of A=B=C=D, then the point should be at the
> centre of the diamond. If A>B and B=C=D=0, Then the point should be at the
> corner of A.
>
> For diamond, how to convert the value of A,B,C,D into cartesian
> co-ordinates ?. if x1,x2,y1,y2 are A,B,C,D, then someone suggested:
>
> new_point<- function(x1, x2, y1, y2, grad=1.73206){
> b1<- y1-(grad*x1)
> b2<- y2-(-grad*x2)
> M<- matrix(c(grad, -grad, -1,-1), ncol=2)
> intercepts<- as.matrix(c(b1,b2))
> t_mat<- -solve(M) %*% intercepts
> data.frame(x=t_mat[1,1], y=t_mat[2,1])
> }
> But this is not working. Please do suggest some help.
> thanks and best regards,
> Alaguraj.V
>
Hi Alaguraj,
A lot depends upon what you mean by "diamond". A rhombus is out because
you say that the lengths of the sides can be different (and as you note,
the answer is easy). If you mean a parallelogram (opposite sides are
equal) the answer is also easy, the intersection of the lines joining
opposite vertices. If you mean a kite (sides of equal length are
adjacent) it is a matter of finding the point along the line joining the
two vertices that join the two sets of equal sides. I suspect that what
you have to calculate is the centroid of a quadrilateral with arbitrary
length sides. We can probably assume that it is convex, as Rolf noted,
as the centroid may be outside quadrilaterals that are very concave
(think boomerang, sport). So if you could tell us a bit more about what
constraints you wish to place on your quadrilateral, somebody may be
able to help.
Jim
More information about the R-help
mailing list