k = 1
Shape(k).Index = 1
Shape(k).CtrRot.x = 130
Shape(k).CtrRot.y = 130
i = 0
i = i + 1
r
= 100 + 40 * COS(3 * j
) PointChain
(k
, i
).x
= 0 + r
* COS(j
) PointChain
(k
, i
).y
= 0 + r
* SIN(j
)Shape(k).Length = i
Shape(k).Omega = 0
Shape
(k
).Shade
= _RGB(255, 255, 255)
'k = 2
'Shape(k).Index = 1
'Shape(k).CtrRot.x = 130
'Shape(k).CtrRot.y = 130
'i = 0
'FOR j = 0 TO 6.28 STEP .01
' i = i + 1
' r = 30
' PointChain(k, i).x = 200 + r * COS(j)
' PointChain(k, i).y = 200 + r * SIN(j)
'NEXT
'Shape(k).Length = i
'Shape(k).Omega = 0
'Shape(k).Shade = _RGB(0, 255, 255)
'CALL CalculateCtrMass(k)
'CALL CalculateMOI(k)
gravity.x = 0
gravity.y = -.4
Shape(1).CtrRot.x = x
Shape(1).CtrRot.y = y
Shape(1).Omega = 0
vtemp.x = x - Shape(1).CtrMass.x
vtemp.y = y - Shape(1).CtrMass.y
CALL TranslateShape
(1, vtemp
) Shape(1).Omega = 0
Shape(1).CtrRot.x = 0
Shape(1).CtrRot.y = 0
vtemp.x = 0 - Shape(1).CtrMass.x
vtemp.y = 0 - Shape(1).CtrMass.y
CALL TranslateShape
(1, vtemp
) Shape(1).Omega = 0
dx = Shape(ShapeIndex).CtrMass.x - Shape(ShapeIndex).CtrRot.x
dy = Shape(ShapeIndex).CtrMass.y - Shape(ShapeIndex).CtrRot.y
torque = dx * gravity.y - dy * gravity.x
Shape(ShapeIndex).Omega = Shape(ShapeIndex).Omega + torque / Shape(ShapeIndex).MOI
CALL RotShape
(ShapeIndex
, Shape
(ShapeIndex
).CtrRot
, Shape
(ShapeIndex
).Omega
)
LOCATE 1, 1:
PRINT "Mouse1 = Change axis -- Mouse2 = Change position -- Space = Reset" FOR i
= 1 TO Shape
(ShapeIndex
).Length
CALL cpset
(PointChain
(ShapeIndex
, i
).x
, PointChain
(ShapeIndex
, i
).y
, Shape
(ShapeIndex
).Shade
) CALL ccircle
(Shape
(ShapeIndex
).CtrMass.x
, Shape
(ShapeIndex
).CtrMass.y
, 3, Shape
(ShapeIndex
).Shade
) CALL ccircle
(Shape
(ShapeIndex
).CtrRot.x
, Shape
(ShapeIndex
).CtrRot.y
, 3, Shape
(ShapeIndex
).Shade
) CALL cline
(Shape
(ShapeIndex
).CtrMass.x
, Shape
(ShapeIndex
).CtrMass.y
, Shape
(ShapeIndex
).CtrRot.x
, Shape
(ShapeIndex
).CtrRot.y
, Shape
(ShapeIndex
).Shade
)
xx = 0
yy = 0
FOR i
= 1 TO Shape
(k
).Length
xx = xx + PointChain(k, i).x
yy = yy + PointChain(k, i).y
Shape(k).CtrMass.x = xx / Shape(k).Length
Shape(k).CtrMass.y = yy / Shape(k).Length
xx = 0
yy = 0
FOR i
= 1 TO Shape
(k
).Length
xx = xx + (Shape(k).CtrRot.x - PointChain(k, i).x) ^ 2
yy = yy + (Shape(k).CtrRot.y - PointChain(k, i).y) ^ 2
Shape(k).MOI = (xx + yy) / Shape(k).Length
FOR i
= 1 TO Shape
(k
).Length
PointChain(k, i).x = PointChain(k, i).x + c.x
PointChain(k, i).y = PointChain(k, i).y + c.y
' Move center of mass.
Shape(k).CtrMass.x = Shape(k).CtrMass.x + c.x
Shape(k).CtrMass.y = Shape(k).CtrMass.y + c.y
FOR i
= 1 TO Shape
(k
).Length
xx = PointChain(k, i).x - c.x
yy = PointChain(k, i).y - c.y
PointChain
(k
, i
).x
= c.x
+ xx
* COS(da
) - yy
* SIN(da
) PointChain
(k
, i
).y
= c.y
+ yy
* COS(da
) + xx
* SIN(da
) ' Move center of mass.
xx = Shape(k).CtrMass.x - c.x
yy = Shape(k).CtrMass.y - c.y
Shape
(k
).CtrMass.x
= c.x
+ xx
* COS(da
) - yy
* SIN(da
) Shape
(k
).CtrMass.y
= c.y
+ yy
* COS(da
) + xx
* SIN(da
)