physics.addBody chain not aligned with polygon of same shape

I am trying to create a series of complex polygons via display.newPolygon and associate them a physics body with the same outline.

I can’t seem to be able to use an outline body since I don’t have an image to use, so I did it like this. Size of the content area is 800x1200.

Here is the relevant part of code where both the polygon and the physics edge shape body are created:

-- cookedHotspots contains couples of values which form the polygon and the chain. They are numbers with many decimals, e.g -- 9.6960542, 45.05634919999999 -- .... for i = 1, #cookedHotspots do local a, b = lonLat2XY(cookedHotspots[i][1], cookedHotspots[i][2]) arenas[i] = display.newPolygon(a + 800 / 2, b + 1200 / 2, cookedHotspots[i][4]) arenas[i].fill = {1,1,1} -- aggiunta fisicità physics.addBody(arenas[i], "static", {chain = cookedHotspots[i][4], connectFirstAndLastChainVertex = true}) end

No matter what I try, there is a misalignment between the polygon and the edge shape body, as shown by the following picture:
 

[sharedmedia=core:attachments:4217]

If I increase the size of the bounding box to accomodate more polygons, the misalignment increases wildly, same data passed. 

[sharedmedia=core:attachments:4218]

Any idea of why it happens? I can only think of different ways of rounding between the polygon code and the physics code since I am passing the exact same vertex structure to both the polygon constructor and the physics body.

 

Update: I tried to trace the polygon with a line object using the same coordinates. As it is visible, the line (in red) and the polygon coincide, but the physics body doesn’t. All three are plotted from the same data.

[sharedmedia=core:attachments:4225]

Ok, looks like I was able to at least align the physics body and the polygon (but not sure is in the right overall position, will need to test).

Apparently, when creating a polygon no matter what coordinates you give, you will not be able to directly specify the absolute position of its vertexes as they get relativized to the center or centroid that needs to be specified during creation (which might or might not be what is desired. I would really love to have a way to specify absolute content coordinates THEN let Corona find or define the center to the polygon. It would help in precise placement of shapes, need to test this better. So far, finding the center of object and using it seemed to work …)

The physics object, instead, needs coordinates relative to that center (i.e. the coordinate values you pass to display.setPolygon(), so I need to subtract the center coordinates to the coordinates of the vertexes.
 

Hi @max00,

I responded to your other post with a solution…

Brent

Update: I tried to trace the polygon with a line object using the same coordinates. As it is visible, the line (in red) and the polygon coincide, but the physics body doesn’t. All three are plotted from the same data.

[sharedmedia=core:attachments:4225]

Ok, looks like I was able to at least align the physics body and the polygon (but not sure is in the right overall position, will need to test).

Apparently, when creating a polygon no matter what coordinates you give, you will not be able to directly specify the absolute position of its vertexes as they get relativized to the center or centroid that needs to be specified during creation (which might or might not be what is desired. I would really love to have a way to specify absolute content coordinates THEN let Corona find or define the center to the polygon. It would help in precise placement of shapes, need to test this better. So far, finding the center of object and using it seemed to work …)

The physics object, instead, needs coordinates relative to that center (i.e. the coordinate values you pass to display.setPolygon(), so I need to subtract the center coordinates to the coordinates of the vertexes.
 

Hi @max00,

I responded to your other post with a solution…

Brent