Download line2.zip
See the definition of classes
Line2 and
Vec2.
main.cpp/* main
*/
#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;
#include "line2.h"
void test1();
void test2();
int main()
{
test1();
cout << "main program done"<<endl;
return 0;
}
void test2()
{
Vec2 a, b;
cout << "Enter two points: ";
cin >> a >> b;
Line2 AB(a,b);
cout << "Line " << AB;
cout << " length " << AB.getSize() << ", angle " << AB.getAngle() << endl;
}
void test1()
{
Vec2 a(14,20);
Vec2 b(4,-3);
Vec2 c(6,8);
Vec2 d(-8,4);
Line2 AB(a,b);
Line2 CD(c,d);
cout << "sizeof(Vec2)-2*sizeof(double) = " << sizeof(Vec2)-2*sizeof(double) << endl;
cout << "sizeof(Line2)-2*sizeof(Vec2) = " << sizeof(Line2)-2*sizeof(Vec2) << endl;
cout << "line AB: " << AB << endl;
cout << "line CD: " << CD << endl;
cout << "line AB + Vec2(1,-1): " << AB+Vec2(1,-1) << endl;
cout << "getSize AB : " << AB.getSize() << endl;
cout << "AB[0][0]: " << AB[0][0] << " AB[0][1]: " << AB[0][1] << endl;
cout << "angle(AB,CD) : " << angle(AB,CD) << endl;
Line2 XY;
cout << "XY.from(0,1).to(3,2): " << XY.from(0,1).to(3,2) << endl;
cout << "XY.to(a).from(b): " << XY.to(a).from(b) << endl;
cout << "Vec2(30.0): " << Vec2(30.0) << endl;
cout << "Line2(1,2,3,4): " << Line2(1,2,3,4) << endl;
Line2 R1(Vec2(30.0));
cout << "R1 = Line2(Vec2(30.0)): " << R1 << endl;
cout << "R1+=a: " << (R1+=a) << endl;
Line2 R2;
R2.from(1,1).away(1.0,-90.0);
cout << "R2 = from(1,1).away(1.0,-90.0) " << R2 << endl;
cout << "test1 done" << endl;
}
C:\classes\ece538\Lines>test1 sizeof(Vec2)-2*sizeof(double) = 0 sizeof(Line2)-2*sizeof(Vec2) = 0 line AB: [14 20]:[4 -3] line CD: [6 8]:[-8 4] line AB + Vec2(1,-1): [15 19]:[5 -4] getSize AB : 25.0799 AB[0][0]: 14 AB[0][1]: 20 angle(AB,CD) : -50.556 XY.from(0,1).to(3,2): [0 1]:[3 2] XY.to(a).from(b): [4 -3]:[14 20] Vec2(30.0): [0.866025 0.5] Line2(1,2,3,4): [1 2]:[3 4] R1 = Line2(Vec2(30.0)): [0 0]:[0.866025 0.5] R1+=a: [14 20]:[14.866 20.5] R2 = from(1,1).away(1.0,-90.0) [1 1]:[1 0] test1 done main program done
Maintained by John Loomis, updated Sat Feb 03 11:15:48 2007