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 [[alternative HTML version deleted]]
Your question makes absolutely no sense at all. See inline below. On 14/03/14 08:03, 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.Which centroid? A "diamond" (convex quadrilateral?) has 3 well defined centroids, in general all different.> The 4 edges are A, B, C, D.Are A, B, C, and D the *lengths* of the edges? Or are they just labels for the edges?> 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,Since we are apparently talking about numerical values here it would seem that A, B, C, and D are the lengths of the sides. How can you have a "diamond" (convex quadrilateral?) with 3 sides of length 0 and the other non-zero?> Then the point should be at the corner of A.What ***on earth*** does "the corner of A" mean?> > 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.Try using Google. Wikipedia has a good article on quadrilaterals and outlines a procedure for finding the area centroid (I presume that's what you actually want) of a convex quadrilateral. cheers, Rolf Turner
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