proj home

Files   Classes   Functions   Hierarchy  

d2arrow Class Reference

Arrow in 2D to aid in visualization. More...

#include <d2arrow.h>

Inheritance diagram for d2arrow:
Collaboration diagram for d2arrow:

List of all members.

Public Member Functions

 d2arrow (doublec arrowlength, doublec headlength)
 Construct an arrow along the x-axis.
 d2arrow (point2< double > const &pi0, doublec theta, doublec arrowlength, doublec headlength)
 Construct an arrow at the point and rotate it.
 d2arrow (point2< double > const &q0, point2< double > const &q1, doublec arrowlength, doublec headlength)
 Construct a normal.
void draw ()
 Draw the arrow.
void rotate (doublec theta)
 Rotate the arrow about pi[0] by theta radians.
void translate (point2< double > const &x)
 Shift the arrow by x.
void constructOnXaxis (doublec arrowlength, doublec headlength)
 Construct an arrow along the x-axis.

Public Attributes

point2< double > pi [4]
 Arrow geometry.

Static Public Attributes

static double headlengthfactor = 0.8
 Change how fat or thin the arrow head is.


Detailed Description

Arrow in 2D to aid in visualization.

The arrow can be constructed in several ways. The simplest is along the x-axis where I would then use OpenGL to do the transformations. A normal can be constructed given two points which is really useful. The standard generic position and angle is there too.

The arrows geometric points are public so if the client wishes to use this class efficiently they should directly apply any transforms to the points and call draw() rather than using this classes transformations.

Arrow point geometry for pi[].

2 \ \ 0 -------------------- 1 / / 3 arrowlength = distance(0,1) headlength = the distance from 1 to intersecting line (2,3) head height = distance(2,3)

Definition at line 36 of file d2arrow.h.


Constructor & Destructor Documentation

d2arrow::d2arrow ( doublec  arrowlength,
doublec  headlength 
)

Construct an arrow along the x-axis.

Definition at line 30 of file d2arrow.cpp.

00034 {
00035   constructOnXaxis(arrowlength,headlength);
00036 }

d2arrow::d2arrow ( point2< double > const &  pi0,
doublec  theta,
doublec  arrowlength,
doublec  headlength 
)

Construct an arrow at the point and rotate it.

Definition at line 39 of file d2arrow.cpp.

00045 {
00046   constructOnXaxis(arrowlength,headlength);
00047   translate(pi0);
00048   rotate(theta);
00049 }

d2arrow::d2arrow ( point2< double > const &  q0,
point2< double > const &  q1,
doublec  arrowlength,
doublec  headlength 
)

Construct a normal.

The arrow is rotated 90 degrees to line (q0,q1) with the base of the arrow in between q0 and q1.

Definition at line 52 of file d2arrow.cpp.

References point2< T >::normalize(), point2< T >::x, and point2< T >::y.

00058 {
00059   // Using vector calculus to calculate the arrows
00060   // geometry points.
00061 
00062   // Construct unit vectors z1 and z2 where z2 is the normal.
00063   // Further z1 = z2 rotated 90 degrees anticlockwise direction.
00064 
00065   // z1 and z2 are at right angles and form a coordinate system.
00066 
00067   point2<double> z1(q1-q0);
00068   z1.normalize();
00069   point2<double> z2(-z1.y,z1.x);
00070 
00071   // The head base of the arrow.
00072   point2<double> hb(z2);
00073   hb *= (arrowlength-headlength);
00074 
00075   // Half the hight of the arrow head.
00076   double w = headlength*headlengthfactor*0.5;
00077 
00078   pi[2] = hb - z1 * w;
00079   pi[3] = hb + z1 * w;
00080   pi[1] = z2*arrowlength;
00081   pi[0] = point2<double>(0.0,0.0);
00082 
00083   point2<double> p0(q0+q1);
00084   p0 *= 0.5;
00085   translate(p0);
00086 }


Member Function Documentation

void d2arrow::constructOnXaxis ( doublec  arrowlength,
doublec  headlength 
)

Construct an arrow along the x-axis.

Definition at line 90 of file d2arrow.cpp.

00094 {
00095   assert(arrowlength>headlength);
00096   assert(arrowlength>0.0);
00097 
00098   pi[0] = point2<double>(0.0,0.0);
00099   pi[1] = point2<double>(arrowlength,0.0);
00100   doublec q = arrowlength-headlength;
00101   doublec arrowheight = headlength*headlengthfactor*0.5;
00102   pi[2] = point2<double>(q,arrowheight);
00103   pi[3] = point2<double>(q,-arrowheight);
00104 }

void d2arrow::draw (  )  [virtual]

Draw the arrow.

Implements gobj.

Definition at line 106 of file d2arrow.cpp.

References pi.

Referenced by d2simplexNormals::draw().

00107 {
00108   glBegin(GL_LINES);
00109 
00110   glVertex3f(pi[0].x,pi[0].y,0.0);
00111   glVertex3f(pi[1].x,pi[1].y,0.0);
00112 
00113   glEnd();
00114 
00115   glBegin(GL_TRIANGLES);
00116 
00117   glVertex3f(pi[1].x,pi[1].y,0.0);
00118   glVertex3f(pi[2].x,pi[2].y,0.0);
00119   glVertex3f(pi[3].x,pi[3].y,0.0);
00120 
00121   glEnd();
00122 }

void d2arrow::rotate ( doublec  theta  ) 

Rotate the arrow about pi[0] by theta radians.

Definition at line 19 of file d2arrow.cpp.

References d2homogeneous::matrixMultiply(), pi, and d2homogeneous::setRotateAboutPoint().

00020 {
00021   d2homogeneous R;
00022 
00023   R.setRotateAboutPoint(theta,pi[0]);
00024 
00025   for (uint i=1; i<4; ++i)
00026     R.matrixMultiply(pi[i]);
00027 }

void d2arrow::translate ( point2< double > const &  x  ) 

Shift the arrow by x.

Definition at line 13 of file d2arrow.cpp.

References pi.

00014 {
00015   for (uint i=0; i<4; ++i)
00016     pi[i] += x; 
00017 }


Member Data Documentation

double d2arrow::headlengthfactor = 0.8 [static]

Change how fat or thin the arrow head is.

This multiplied by the headlength gives the height of the arrow head.

Definition at line 45 of file d2arrow.h.

point2<double> d2arrow::pi[4]

Arrow geometry.

Definition at line 41 of file d2arrow.h.

Referenced by draw(), rotate(), and translate().


The documentation for this class was generated from the following files:

Generated on Fri Mar 4 00:49:52 2011 for Chelton Evans Source by  doxygen 1.5.8