title: Calculate triangle areas - R
body: <p>I am trying to calculate triangle area of pair of running points (X1, Y1,…. Xn, Yn) with a fix point (Cx,Cy) but without success. Can someone tell  me please what is the problem so I can try to solve it?</p>
  
  <p>Script:</p>
  
  <pre><code>library(ggplot2)
  
  nElem &lt;- 100
  xData &lt;- as.data.frame(seq(1,nElem,5))
  yData &lt;- as.data.frame(seq(5,nElem,5))
  xyDATA&lt;- cbind(xData,yData)
  colnames(xyDATA) &lt;- c("xCoord","yCoord")
  
  Cx &lt;- 10
  Cy &lt;- 1
  
  ggplot(xyDATA) + geom_point(aes(x = xCoord, y = yCoord)) + geom_point(aes(x = Cx, y = Cy),colour="red",size=4)
  
  for(i in 1:19) 
  {
    Ax &lt;- xyDATA[i,1]
    Ay &lt;- xyDATA[i,2]
    Bx &lt;- xyDATA[i+1,1]
    By &lt;- xyDATA[i+1,2]
  
  
    s &lt;-  abs(0.5*((Ax*(By-Cy))+(Bx*(Cy-Ay))+(Cx*(Ay-By))))
    # print(Ax)
    # print(Ay)
    # print(Bx)
    # print(By)
    print(s)
  }
  </code></pre>