Title: corona lua code - why doesn't this object spin? (i.e. center of mass related test code)
Tags: lua;coronasdk
Question: Can someone explain why the rectangle doesn't spin here?   This is Lua code and I'm using Corona SDK.
That is, I've tried to set up a rectangle with it's centre of mass off-center, and then apply a force to it in the middle, expecting it to spin as it's center of mass is off....
display.setStatusBar( display.HiddenStatusBar )
-- Setup
local screenCenterX, screenCenterY =  display.contentWidth/2, display.contentHeight/2
-- Create Object
local myRect = display.newRect(0, 0, 30, 90)
myRect.strokeWidth = 2
myRect:setFillColor(140, 140, 140, 0)
myRect:setStrokeColor(180, 180, 180)
myRect:setReferencePoint(display.CenterReferencePoint)
myRect.x, myRect.y = screenCenterX, screenCenterY
-- Apply Physics
local physics = require("physics")
physics.start()
physics.setGravity(0,0)
physics.addBody( myRect, "kinimatic", { friction=0.5, bounce=0.1, radius = 45 } )
-- Redefine Centre of Mass (what I'm trying to get right)
myRect.xOrigin, myRect.yOrigin = screenCenterX, screenCenterY - 100
-- Replace myRect to the center as setting the xOrigin/yOrigin seems to have moved it
myRect.x, myRect.y = screenCenterX, screenCenterY
-- Apply Force
timer.performWithDelay(3000,
function(event)
myRect:applyForce(5,0,  screenCenterX, screenCenterY)
-- WHY DOES THIS NOT SPIN THE OBJECT???
-- Centre of gravity has been change so shouldn't it rotate now?
-- That is, trying to simulate applying a force to an object who's centre of mass is NOT in
-- the center, and then see it spin.
end

Here is the accepted answer: The variables xOrigin and yOrigin are used only to move a object, those variables cannot affect physics at all, and they are not really a "origin" (they are the x/y position of a object in relation of the parent "x/yOrigin" variable).
To do a unbalanced physics object, you need to do it with the shapes, so you will have to create two shapes (thus you cannot use automatic shapes, you will have to use polygon), with one of them being heavier than the other to simulate the off-center mass.
For example a rectangle with 100 units in length, you make 50 units weight 1, and the other 50 units weight 2, the result would be the center being at x 75 more or less (my math may be wrong here).


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2012:00:08/21/12', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<lua><coronasdk>', 'Title': "corona lua code - why doesn't this object spin? (i.e. center of mass related test code)", 'ViewCount': 628, 'id': 12048062, 'user_AboutMe': None, 'user_AccountId': 57924.0, 'user_DisplayName': 'Greg', 'user_Reputation': 33362.0, 'user_Views': 1586.0, 'user_id': 173520.0}}