[Jderobot-admin] jderobot-r958 - in trunk/src/libs/geometry: . math

eperdices en jderobot.org eperdices en jderobot.org
Jue Ago 1 23:49:03 CEST 2013


Author: eperdices
Date: 2013-08-01 23:48:02 +0200 (Thu, 01 Aug 2013)
New Revision: 958

Added:
   trunk/src/libs/geometry/math/Line2D.cpp
   trunk/src/libs/geometry/math/Line2D.h
Modified:
   trunk/src/libs/geometry/CMakeLists.txt
Log:
A?\195?\177adida clase line2D



Modified: trunk/src/libs/geometry/CMakeLists.txt
===================================================================
--- trunk/src/libs/geometry/CMakeLists.txt	2013-08-01 10:42:10 UTC (rev 957)
+++ trunk/src/libs/geometry/CMakeLists.txt	2013-08-01 21:48:02 UTC (rev 958)
@@ -5,7 +5,8 @@
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} /usr/include/libxml2/)
  
 ADD_LIBRARY(geometry_shared SHARED math/matriz3x3.cpp  math/matriz4x4.cpp  math/plano.cpp  math/recta.cpp  
-				   math/segmento.cpp  math/utils.cpp  math/vector2d.cpp  math/vector2H.cpp  math/vector3.cpp  math/vector3H.cpp 
+				   math/segmento.cpp  math/utils.cpp  math/vector2d.cpp  math/vector2H.cpp  math/vector3.cpp  math/vector3H.cpp
+				   math/Line2D.cpp 
                                    collada/colladaparser.cpp collada/color.cpp collada/malla.cpp collada/material.cpp collada/submalla.cpp progeo/progeo.cpp)
 
 target_link_libraries(geometry_shared tinyxml GLU )
@@ -14,6 +15,7 @@
  
 ADD_LIBRARY(geometry_static STATIC math/matriz3x3.cpp  math/matriz4x4.cpp  math/plano.cpp  math/recta.cpp  
                                    math/segmento.cpp  math/utils.cpp  math/vector2d.cpp  math/vector2H.cpp  math/vector3.cpp  math/vector3H.cpp 
+                                   math/Line2D.cpp
                                    collada/colladaparser.cpp collada/color.cpp collada/malla.cpp collada/material.cpp collada/submalla.cpp progeo/progeo.cpp)
 
 target_link_libraries(geometry_shared tinyxml GLU ) 

Added: trunk/src/libs/geometry/math/Line2D.cpp
===================================================================
--- trunk/src/libs/geometry/math/Line2D.cpp	                        (rev 0)
+++ trunk/src/libs/geometry/math/Line2D.cpp	2013-08-01 21:48:02 UTC (rev 958)
@@ -0,0 +1,64 @@
+#include "Line2D.h"
+
+Line2D::Line2D() {
+  this->v.setZero();
+}
+
+Line2D::Line2D(double p1x, double p1y, double p2x, double p2y) {
+  this->v = this->getLine(p1x, p1y, p2x, p2y);
+}
+
+Line2D::Line2D(Eigen::Vector2d p1, Eigen::Vector2d p2) {
+  this->v = this->getLine(p1, p2);
+}
+
+Line2D::Line2D(double va, double vb, double vc) {
+  this->v << va, vb, vc;
+}
+
+Line2D::Line2D(Eigen::Vector3d v) {
+  this->v = v;
+}
+
+Eigen::Vector3d
+Line2D::getVector() {
+  return this->v;
+}
+
+Eigen::Vector3d
+Line2D::getLine(double p1x, double p1y, double p2x, double p2y) {
+  Eigen::Vector3d v;
+
+  /*Get the Ax + By + C = 0 parameters*/
+	v(0) = p1y - p2y;           //y1*z2 - z1*y2
+	v(1) = p2x - p1x;           //z1*x2 - x1*z2
+	v(2) = p1x*p2y - p1y*p2x; 	//x1*y2 - y1*x2
+
+  return v;
+}
+
+Eigen::Vector3d
+Line2D::getLine(Eigen::Vector2d p1, Eigen::Vector2d p2) {
+  Eigen::Vector3d v;
+
+  /*Get the Ax + By + C = 0 parameters*/
+	v(0) = p1(1) - p2(1);               //y1*z2 - z1*y2
+	v(1) = p2(0) - p1(0);               //z1*x2 - x1*z2
+	v(2) = p1(0)*p2(1) - p1(1)*p2(0); 	//x1*y2 - y1*x2
+
+  return v;
+}
+
+Line2D
+Line2D::getNormalLine(double px, double py) {
+  Eigen::Vector3d vn;
+  double nA, nB, nC;
+
+  /*Calc the normal*/
+  vn(0) = this->v(1);
+  vn(1) = -this->v(0);
+  vn(2) = -(px*vn(0) + py*vn(1)); //Solve equation Ax+By+C with central point
+
+  return Line2D(vn);
+}
+


Property changes on: trunk/src/libs/geometry/math/Line2D.cpp
___________________________________________________________________
Added: svn:executable
   + *

Added: trunk/src/libs/geometry/math/Line2D.h
===================================================================
--- trunk/src/libs/geometry/math/Line2D.h	                        (rev 0)
+++ trunk/src/libs/geometry/math/Line2D.h	2013-08-01 21:48:02 UTC (rev 958)
@@ -0,0 +1,34 @@
+/*Represents a 2D line with the general equation of the line: Ax+By+C = 0*/
+
+#ifndef LINE2D_H
+#define LINE2D_H
+#define EIGEN_DONT_ALIGN_STATICALLY True
+
+#include <math.h>
+#include <eigen3/Eigen/Dense>
+
+class Line2D{
+public:
+  Line2D();
+  Line2D(double p1x, double p1y, double p2x, double p2y);
+  Line2D(Eigen::Vector2d p1, Eigen::Vector2d p2);
+  //Line2D(Point2D p1, Point2D p2);
+  Line2D(double va, double vb, double vc);
+  Line2D(Eigen::Vector3d v);
+
+  Eigen::Vector3d getVector();
+
+  /*Calculate line from 2 2D points*/
+  Eigen::Vector3d getLine(double p1x, double p1y, double p2x, double p2y);
+  Eigen::Vector3d getLine(Eigen::Vector2d p1, Eigen::Vector2d p2);
+
+  /*Calculate a 2D normal line from current 2D line and a 2D point*/
+  Line2D getNormalLine(double px, double py);
+  
+private:
+
+  Eigen::Vector3d v;
+    
+};
+
+#endif


Property changes on: trunk/src/libs/geometry/math/Line2D.h
___________________________________________________________________
Added: svn:executable
   + *



More information about the Jderobot-admin mailing list