if provide with accelerometer, gyroscope and other sensor if needed, how to find the center of gravity (say Segway)

Same condition as above, how to find the center of gravity dynamically. (say Segway, every time you put some weight on different part of Segway, how do you find the new centre of gravity again automatically?)

from what I understand of the segway (which isn't much and is probably wrong), it doesn't actually need to find the center of gravity, it just applies however much power is needed to whichever direction to keep itself upright.