I’m trying to draw a filled-in arc from a point represented by a ship’s x,y location. I have it working using some code posted previously to the forums in one case, when the angle is 0 and the anchor points are anchorX = 0, anchorY = 0.5
But when the arc(polygon) has to be rotated to match the rotation of the ship, it becomes misaligned.
So presumably I have to alter the anchor points in relation to the ship rotation to ensure that the arc originates at the proper point. I suspect it’s anchorX = math.cos(?) * ? and anchorY = math.sin(?) * ? but the answer isn’t obvious to me. Anyone have any suggestions? Thanks.
Here’s the function code:
function ship.drawArc(startAngle, widthAngle, radius ) startAngle = startAngle or 0 widthAngle = widthAngle or 90 radius = radius or 100 local vert = {} vert[#vert+1] = 0 vert[#vert+1] = 0 for i = 0, widthAngle do local a = (startAngle+i)\*math.pi/180 vert[#vert+1] = radius \* math.cos(a) vert[#vert+1] = radius \* math.sin(a) end local arc = display.newPolygon(0, 0, vert) arc:setFillColor(1,1,1) arc.strokeWidth = 1 arc:setStrokeColor( 1, 1, 1 ) arc.rotation = ship.rotation arc.anchorX, arc.anchorY = 0, .5 -- correct when ship faces 0 degrees return arc end