• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

step/stepcore

  • sources
  • kde-4.12
  • kdeedu
  • step
  • stepcore
motor.cc
Go to the documentation of this file.
1 /* This file is part of StepCore library.
2  Copyright (C) 2007 Vladimir Kuznetsov <ks.vladimir@gmail.com>
3 
4  StepCore library is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  StepCore library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with StepCore; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
19 #include "motor.h"
20 #include "rigidbody.h"
21 #include "particle.h"
22 #include <cmath>
23 #include <QtGlobal>
24 
25 namespace StepCore
26 {
27 
28 STEPCORE_META_OBJECT(LinearMotor, QT_TRANSLATE_NOOP("ObjectClass", "LinearMotor"), QT_TR_NOOP("Linear motor: applies a constant force to a given position of the body"), 0,
29  STEPCORE_SUPER_CLASS(Item) STEPCORE_SUPER_CLASS(Force),
30  STEPCORE_PROPERTY_RW(Object*, body, QT_TRANSLATE_NOOP("PropertyName", "body"), STEPCORE_UNITS_NULL, QT_TR_NOOP("Body"), body, setBody)
31  STEPCORE_PROPERTY_RW(StepCore::Vector2d, localPosition, QT_TRANSLATE_NOOP("PropertyName", "localPosition"), QT_TRANSLATE_NOOP("Units", "m"), QT_TR_NOOP("Position of the motor on a body"), localPosition, setLocalPosition)
32  STEPCORE_PROPERTY_RW(StepCore::Vector2d, forceValue, QT_TRANSLATE_NOOP("PropertyName", "forceValue"), QT_TRANSLATE_NOOP("Units", "N"), QT_TR_NOOP("Value of the force, acting on the body"), forceValue, setForceValue))
33 
34 STEPCORE_META_OBJECT(CircularMotor, QT_TRANSLATE_NOOP("ObjectClass", "CircularMotor"), QT_TR_NOOP("Circular motor: applies a constant torque to the body"), 0,
35  STEPCORE_SUPER_CLASS(Item) STEPCORE_SUPER_CLASS(Force),
36  STEPCORE_PROPERTY_RW(Object*, body, QT_TRANSLATE_NOOP("PropertyName", "body"), STEPCORE_UNITS_NULL, QT_TR_NOOP("Body"), body, setBody)
37  STEPCORE_PROPERTY_RW(StepCore::Vector2d, localPosition, QT_TRANSLATE_NOOP("PropertyName", "localPosition"), QT_TRANSLATE_NOOP("Units", "m"), QT_TR_NOOP("Position of the motor on a body"), localPosition, setLocalPosition)
38  STEPCORE_PROPERTY_RW(double, torqueValue, QT_TRANSLATE_NOOP("PropertyName", "torqueValue"), QT_TRANSLATE_NOOP("Units", "N m"), QT_TR_NOOP("Value of the torque, acting on the body"), torqueValue, setTorqueValue))
39 
40 
41 LinearMotor::LinearMotor(Object* body, const Vector2d& localPosition, Vector2d forceValue)
42  : _localPosition(localPosition), _forceValue(forceValue)
43 {
44  setBody(body);
45  setColor(0xff0000ff);
46 }
47 
48 void LinearMotor::calcForce(bool /*calcVariances*/)
49 {
50  if(_p) _p->applyForce(_forceValue);
51  else if(_r) _r->applyForce(_forceValue,
52  _r->pointLocalToWorld(_localPosition));
53 
54 }
55 
56 void LinearMotor::setBody(Object* body)
57 {
58  if(body) {
59  if(body->metaObject()->inherits<Particle>()) {
60  _body = body;
61  _p = static_cast<Particle*>(body);
62  _r = NULL;
63  return;
64  } else if(body->metaObject()->inherits<RigidBody>()) {
65  _body = body;
66  _p = NULL;
67  _r = static_cast<RigidBody*>(body);
68  return;
69  }
70  }
71  _body = NULL;
72  _p = NULL;
73  _r = NULL;
74 }
75 
76 Vector2d LinearMotor::position() const
77 {
78  if(_p) return _p->position() + _localPosition;
79  else if(_r) return _r->pointLocalToWorld(_localPosition);
80  return _localPosition;
81 }
82 
83 /*
84 void LinearMotor::worldItemRemoved(Item* item)
85 {
86  if(item == NULL) return;
87  if(item == _body) setBody(NULL);
88 }
89 
90 void LinearMotor::setWorld(World* world)
91 {
92  if(world == NULL) {
93  setBody(NULL);
94  } else if(this->world() != NULL) {
95  if(_body != NULL) setBody(world->item(body()->name()));
96  }
97  Item::setWorld(world);
98 }
99 */
100 
102 CircularMotor::CircularMotor(Object* body, const Vector2d& localPosition, double torqueValue)
103  : _localPosition(localPosition), _torqueValue(torqueValue)
104 {
105  setBody(body);
106  setColor(0xff0000ff);
107 }
108 
109 void CircularMotor::calcForce(bool /*calcVariances*/)
110 {
111  if(_r) _r->applyTorque(_torqueValue);
112 }
113 
114 void CircularMotor::setBody(Object* body)
115 {
116  if(body) {
117  if(body->metaObject()->inherits<RigidBody>()) {
118  _body = body;
119  _r = static_cast<RigidBody*>(body);
120  return;
121  }
122  }
123  _body = NULL;
124  _r = NULL;
125 }
126 
127 Vector2d CircularMotor::localPosition() const
128 {
129  if(_r) return Vector2d::Zero();
130  else return _localPosition;
131 }
132 
133 Vector2d CircularMotor::position() const
134 {
135  if(_r) return _r->position();
136  return _localPosition;
137 }
138 
139 /*
140 void CircularMotor::worldItemRemoved(Item* item)
141 {
142  if(item == NULL) return;
143  if(item == _body) setBody(NULL);
144 }
145 
146 void CircularMotor::setWorld(World* world)
147 {
148  if(world == NULL) {
149  setBody(NULL);
150  } else if(this->world() != NULL) {
151  if(_body != NULL) setBody(world->item(body()->name()));
152  }
153  Item::setWorld(world);
154 }
155 */
156 
157 } // namespace StepCore
158 
StepCore::RigidBody::applyForce
void applyForce(const Vector2d &force, const Vector2d &position)
Apply force (and torque) to the body at given position (in World coordinates)
Definition: rigidbody.cc:170
rigidbody.h
RigidBody class.
StepCore::LinearMotor::position
Vector2d position() const
Position of the motor.
Definition: motor.cc:76
StepCore::LinearMotor::_p
Particle * _p
Definition: motor.h:80
StepCore::CircularMotor::CircularMotor
CircularMotor(Object *body=0, const Vector2d &localPosition=Vector2d::Zero(), double torqueValue=0)
Constructs CircularMotor.
Definition: motor.cc:102
StepCore::CircularMotor::_r
RigidBody * _r
Definition: motor.h:128
StepCore::Vector2d
Eigen::Vector2d Vector2d
Two-dimensional vector with double components.
Definition: vector.h:29
StepCore::Object
Root of the StepCore classes hierarchy.
Definition: object.h:57
StepCore::CircularMotor::localPosition
Vector2d localPosition() const
Local position of the motor on the body or in the world (if the motor is not connected) ...
Definition: motor.cc:127
StepCore::LinearMotor::_r
RigidBody * _r
Definition: motor.h:81
StepCore::RigidBody::position
const Vector2d & position() const
Get position of the center of mass of the body.
Definition: rigidbody.h:160
StepCore::STEPCORE_SUPER_CLASS
STEPCORE_SUPER_CLASS(CollisionSolver)
StepCore::RigidBody
Rigid body.
Definition: rigidbody.h:144
StepCore::CircularMotor::_torqueValue
double _torqueValue
Definition: motor.h:126
motor.h
LinearMotor class.
StepCore::QT_TRANSLATE_NOOP
QT_TRANSLATE_NOOP("ObjectClass","GJKCollisionSolver")
StepCore::Item::setColor
void setColor(Color color)
Set item color (for use in GUI)
Definition: world.h:112
StepCore::LinearMotor::_forceValue
Vector2d _forceValue
Definition: motor.h:78
StepCore::LinearMotor::calcForce
void calcForce(bool calcVariances)
Calculate force.
Definition: motor.cc:48
StepCore::RigidBody::pointLocalToWorld
Vector2d pointLocalToWorld(const Vector2d &p) const
Translate local coordinates on body to world coordinates.
Definition: rigidbody.cc:201
StepCore::CircularMotor::_localPosition
Vector2d _localPosition
Definition: motor.h:125
StepCore::CircularMotor::calcForce
void calcForce(bool calcVariances)
Calculate force.
Definition: motor.cc:109
StepCore::QT_TR_NOOP
QT_TR_NOOP("Errors class for CoulombForce")
StepCore::STEPCORE_PROPERTY_RW
STEPCORE_PROPERTY_RW(double, depth, QT_TRANSLATE_NOOP("PropertyName","depth"), QT_TRANSLATE_NOOP("Units","J"), QT_TR_NOOP("Potential depth"), depth, setDepth) STEPCORE_PROPERTY_RW(double
StepCore::RigidBody::applyTorque
void applyTorque(double torque)
Apply torque (but no force) to the body.
Definition: rigidbody.h:205
StepCore::Particle::applyForce
void applyForce(const Vector2d &force)
Apply force to the body.
Definition: particle.h:135
StepCore::CircularMotor::_body
Object * _body
Definition: motor.h:124
StepCore::Particle
Particle with mass.
Definition: particle.h:103
STEPCORE_UNITS_NULL
#define STEPCORE_UNITS_NULL
Definition: object.h:365
StepCore::LinearMotor::body
Object * body() const
Get pointer to the body.
Definition: motor.h:53
StepCore::LinearMotor::_body
Object * _body
Definition: motor.h:76
particle.h
Particle and ChargedParticle classes.
StepCore::LinearMotor::_localPosition
Vector2d _localPosition
Definition: motor.h:77
StepCore::Particle::position
const Vector2d & position() const
Get position of the particle.
Definition: particle.h:117
StepCore::STEPCORE_META_OBJECT
STEPCORE_META_OBJECT(CollisionSolver, QT_TRANSLATE_NOOP("ObjectClass","CollisionSolver"),"CollisionSolver", MetaObject::ABSTRACT, STEPCORE_SUPER_CLASS(Object), STEPCORE_PROPERTY_RW(double, toleranceAbs, QT_TRANSLATE_NOOP("PropertyName","toleranceAbs"), STEPCORE_UNITS_1, QT_TR_NOOP("Allowed absolute tolerance"), toleranceAbs, setToleranceAbs) STEPCORE_PROPERTY_R_D(double, localError, QT_TRANSLATE_NOOP("PropertyName","localError"), STEPCORE_UNITS_1, QT_TR_NOOP("Maximal local error during last step"), localError)) STEPCORE_META_OBJECT(GJKCollisionSolver
StepCore::CircularMotor::setBody
void setBody(Object *body)
Set pointer to the connected body.
Definition: motor.cc:114
StepCore::CircularMotor::position
Vector2d position() const
Position of the motor.
Definition: motor.cc:133
StepCore::CircularMotor::body
Object * body() const
Get pointer to the body.
Definition: motor.h:99
StepCore::LinearMotor::setBody
void setBody(Object *body)
Set pointer to the connected body.
Definition: motor.cc:56
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:43:06 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

step/stepcore

Skip menu "step/stepcore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal