Files at this revision

API Documentation at this revision

Comitter:
lmarketin
Date:
Fri May 07 13:50:19 2021 +0000
Commit message:
ObjectPosition

Changed in this revision

objectPosition.cpp Show annotated file Show diff for this revision Revisions of this file
objectPosition.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r a1659f63e4a2 objectPosition.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/objectPosition.cpp	Fri May 07 13:50:19 2021 +0000
@@ -0,0 +1,62 @@
+#include "objectPosition.h"
+#include <math.h>
+
+
+ObjectPosition::ObjectPosition()
+{
+}
+
+ObjectPosition::ObjectPosition(float angle, float distance) : m_angle((angle)*PI/180), m_distance(distance)
+{
+    m_x = cos(m_angle) * m_distance;
+    m_y = sin(m_angle) * m_distance;
+}
+
+ObjectPosition::ObjectPosition(int x, int y) : m_x(x), m_y(y)
+{
+    m_distance = sqrt((m_x * m_x)+(m_y * m_y));
+    m_angle = atan(m_y / m_x);
+}
+
+ObjectPosition::~ObjectPosition()
+{
+}
+
+void ObjectPosition::setDistance(float distance)
+{
+    m_distance = distance;
+    m_x = cos(m_angle) * m_distance;
+    m_y = sin(m_angle) * m_distance;
+}
+
+void ObjectPosition::setAngle(float angle)
+{
+    m_angle = (angle)*PI/180;
+    m_x = cos(m_angle) * m_distance;
+    m_y = sin(m_angle) * m_distance;
+}
+
+float ObjectPosition::getAngle()
+{
+    return m_angle*180/PI;
+}
+
+float ObjectPosition::getDistance()
+{
+    return m_distance;
+}
+
+double ObjectPosition::getXCoordinate()
+{
+    return m_x;
+}
+
+double ObjectPosition::getYCoordinate()
+{
+    return m_y;
+}
+
+double ObjectPosition::getDistanceFromOtherObj(ObjectPosition* otherObjPos)
+{
+    return sqrt(pow(otherObjPos->getXCoordinate() - this->m_x, 2) + pow(otherObjPos->getYCoordinate() - this->m_y, 2));
+}
diff -r 000000000000 -r a1659f63e4a2 objectPosition.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/objectPosition.h	Fri May 07 13:50:19 2021 +0000
@@ -0,0 +1,39 @@
+#ifndef OBJECTPOSITION_H
+#define OBJECTPOSITION_H
+
+/*
+* This class is used to defined object postion in mornitring area
+*/
+class ObjectPosition
+{
+public:
+    /**Default constructor*/ //IZBRISATI!!??
+    ObjectPosition();
+    
+    /**Constructor by angle and distance*/
+    ObjectPosition(float angle, float dinstance);
+    
+    /**Constructor by x and y coordinates*/
+    ObjectPosition(int x, int y);
+    
+    ~ObjectPosition();
+    void setAngle(float angle);
+    void setDistance(float dinstance);
+    float getAngle();
+    float getDistance();
+    double getXCoordinate();
+    double getYCoordinate();
+    
+    /**Calculating the distance between the position of this object and the position of another object*/
+    double getDistanceFromOtherObj(ObjectPosition* otherObjPos);
+
+private :
+    ObjectPosition* m_otherObjPos;
+    float m_angle;
+    float m_distance;
+    double m_x;
+    double m_y;
+    const static double PI  =3.141592653589793238463;
+    
+};
+#endif