本文整理汇总了C++中Body::getMass方法的典型用法代码示例。如果您正苦于以下问题:C++ Body::getMass方法的具体用法?C++ Body::getMass怎么用?C++ Body::getMass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Body
的用法示例。
在下文中一共展示了Body::getMass方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateCenterOfMass
void updateCenterOfMass(Body body) {
if (_mass == 0) {
_mass = body.getMass();
_centerOfMass = body.getPos();
} else {
double new_mass = _mass + body.getMass();
double new_cen_x = ((_mass*_centerOfMass.getX()) + (body.getMass() * body.getXPos()))/new_mass;
double new_cen_y = ((_mass*_centerOfMass.getY()) + (body.getMass() * body.getYPos()))/new_mass;
_centerOfMass = Vec2D(new_cen_x, new_cen_y);
_mass = new_mass;
}
}
示例2: pow
sf::Vector2f Universe::force(Body p1, Body p2){
sf::Vector2f planet_force;
double totalForce, dx, dy, radius, radius_squared;
double grav = (-6.67e-11);
dx = (((p1.getPosition()).x) - ((p2.getPosition()).x));
dy = (((p1.getPosition()).y) - ((p2.getPosition()).y));
radius_squared = pow(dx, 2) + pow(dy, 2);
radius = sqrt(radius_squared);
totalForce = ((grav) * (p1.getMass()) * (p2.getMass())) / (radius_squared);
planet_force.x = totalForce * (dx/radius);
planet_force.y = totalForce * (dy/radius);
return planet_force;
}
示例3: print
void print() {
cout << "Entering Print" << endl;
if (_state == INTERNAL) {
cout << "Internal" << endl;
if (_body == NULL) {
cout << "NO Body here" << endl;
cout << "Mass of internal node " << _mass << endl;
cout << "Center of Mass " << _centerOfMass.getX() << " " << _centerOfMass.getY() << endl;
} else {
cout << _body->getMass() << endl;
}
}
else {
cout << "External" << endl;
if (_body == NULL) {
cout << "NO Body here" << endl;
} else {
cout << _body->getMass() << endl;
}
}
if (_NW != NULL) {
cout << "Printing NW" << endl;
_NW->print();
}
if (_NE != NULL) {
cout << "Printing NE" << endl;
_NE->print();
}
if (_SW != NULL) {
cout << "Printing SW" << endl;
_SW->print();
}
if (_SE != NULL) {
cout << "Printing SE" << endl;
_SE->print();
}
cout << "Leaving Print" << endl;
}
示例4: calculateForceFromBody
Force calculateForceFromBody(Body otherBody) {
Vec2D distance = calculateDistanceFromBody(otherBody);
Vec2D unit_distance = distance.getUnitVector();
if (distance.getMagnitude() != 0) {
double forceMagnitude= (GRAVITYCONST * otherBody.getMass() * getMass()) / (pow(distance.getMagnitude(), 2));
double forceMagnitude_x = forceMagnitude * unit_distance.getX();
double forceMagnitude_y = forceMagnitude * unit_distance.getY();
return Force(forceMagnitude_x, forceMagnitude_y);
} else {
return Force(0,0);
}
}
示例5: w_Body_getMass
int w_Body_getMass(lua_State * L)
{
Body * t = luax_checkbody(L, 1);
lua_pushnumber(L, t->getMass());
return 1;
}
示例6:
Body(const Body &otherBody) {
_mass = otherBody.getMass();
_vel = otherBody.getVel();
_pos = otherBody.getPos();
_forces = otherBody._forces;
}
示例7: insertBody
bool insertBody(Body body) {
// cout << "In insert" << endl;
if (outOfRange(body)) {
return false;
}
if ((_mass == 0 && isExternal())) {
// cout << "Keeping body here" << endl;
_mass += body.getMass();
_centerOfMass = _centerOfMass + body.getPos();
//_body = new Body(body);
return true;
}
// updateCenterOfMass(body);
Body temp(_mass, 0, 0, _centerOfMass.getX(), _centerOfMass.getY());
if (isExternal()) {
// cout << "is external" << endl;
_mass = 0;
_centerOfMass = Vec2D(0,0);
int quad = getQuadrantOfBody(temp);
if (quad == 1) {
if (_NW == NULL)
_NW = new TreeNode(_box.getQuadrant(1));
_NW->insertBody(temp);
}
if (quad == 2) {
if (_NE == NULL)
_NE = new TreeNode(_box.getQuadrant(2));
_NE->insertBody(temp);
}
if (quad == 3) {
if (_SW == NULL)
_SW = new TreeNode(_box.getQuadrant(3));
_SW->insertBody(temp);
}
if (quad == 4) {
if (_SE == NULL)
_SE = new TreeNode(_box.getQuadrant(4));
_SE->insertBody(temp);
}
// cout << "is external 2 " << endl;
}
int quad = getQuadrantOfBody(body);
if (quad == 1) {
if (_NW == NULL)
_NW = new TreeNode(_box.getQuadrant(1));
_NW->insertBody(body);
}
if (quad == 2) {
if (_NE == NULL)
_NE = new TreeNode(_box.getQuadrant(2));
_NE->insertBody(body);
}
if (quad == 3) {
if (_SW == NULL)
_SW = new TreeNode(_box.getQuadrant(3));
_SW->insertBody(body);
}
if (quad == 4) {
if (_SE == NULL)
_SE = new TreeNode(_box.getQuadrant(4));
_SE->insertBody(body);
}
if (_NW != NULL) {
_mass += _NW->_mass;
_centerOfMass = _centerOfMass + _NW->_mass * _NW->_centerOfMass;
}
if (_NE != NULL) {
_mass += _NE->_mass;
_centerOfMass = _centerOfMass + _NE->_mass * _NE->_centerOfMass;
}
if (_SW != NULL) {
_mass += _SW->_mass;
_centerOfMass = _centerOfMass + _SW->_mass * _SW->_centerOfMass;
}
if (_SE != NULL) {
_mass += _SE->_mass;
_centerOfMass = _centerOfMass + _SE->_mass * _SE->_centerOfMass;
//.........这里部分代码省略.........