LFLineSegment.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "LFLineSegment.h"
00027
00028 void LFLineSegment::Read(FILE* fin)
00029 {
00030 int ret=0;
00031 ret=fscanf(fin, "%lf %lf", &sx_, &sy_);
00032 ret=fscanf(fin, "%lf %lf", &ex_, &ey_);
00033 }
00034
00035 double LFLineSegment::Theta()
00036 {
00037 double theta = atan2(ey_-sy_,ex_-sx_);
00038 if (theta<0)
00039 theta += M_PI;
00040 return theta;
00041 }
00042
00043 void LFLineSegment::Center(double *center)
00044 {
00045 center[0] = (sx_ + ex_) / 2;
00046 center[1] = (sy_ + ey_) / 2;
00047 }
00048
00049 void LFLineSegment::Translate(double *vec)
00050 {
00051 sx_ += vec[0];
00052 sy_ += vec[1];
00053
00054 ex_ += vec[0];
00055 ey_ += vec[1];
00056 }
00057
00058
00059 void LFLineSegment::Rotate(double theta)
00060 {
00061 double x, y;
00062 x = sx_, y = sy_;
00063
00064 double sinTheta;
00065 double cosTheta;
00066 double mat[2][2];
00067
00068 sinTheta = sin(theta);
00069 cosTheta = cos(theta);
00070 mat[0][0] = cosTheta;
00071 mat[0][1] = -sinTheta;
00072 mat[1][0] = sinTheta;
00073 mat[1][1] = cosTheta;
00074
00075 sx_ = x*mat[0][0] + y*mat[0][1];
00076 sy_ = x*mat[1][0] + y*mat[1][1];
00077
00078 x = ex_, y = ey_;
00079 ex_ = x*mat[0][0] + y*mat[0][1];
00080 ey_ = x*mat[1][0] + y*mat[1][1];
00081 }
00082
00083 void LFLineSegment::Scale(double s)
00084 {
00085 sx_ *= s;
00086 sy_ *= s;
00087 ex_ *= s;
00088 ey_ *= s;
00089
00090 }
00091
00092 double LFLineSegment::Length()
00093 {
00094 double x, y;
00095 x = ex_ - sx_;
00096 y = ey_ - sy_;
00097
00098 return sqrt(x*x+y*y);
00099 }