I have a SKSpriteNode which is an image of a equilateral triangle, I want to set it's anchor point at the triangle's centroid so I can get it to rotate smoothly and remain in centre. I have calculated the centroid with the code bellow but these positions are relative to the scene, so I'm not sure how to convert it to the accurate decimals for the anchor point (between 0 and 1).
let XA = triangle.position.x - (triangle.size.width / 2) // left point
let XB = triangle.position.x // top point
let XC = triangle.position.x + (triangle.size.width / 2) // right point
let YA = triangle.position.y - (triangle.size.height / 2) // left point
let YB = triangle.position.y + (triangle.size.height / 2) // top point
let YC = triangle.position.y - (triangle.size.height / 2) // right point
let triCenterX = (XA + XB + XC) / 3.0
let triCenterY = (YA + YB + YC) / 3.0
let centroid = CGPointMake(triCenterX, triCenterY) // 207.0, 412.65
// triangle.anchorPoint = CGPoint(x: , y: )
I'm not sure if I'm on the right track or where to go from here, maybe I need to do this a different way? Any help would be much appreciated, thanks.