00001 /* 00002 Copyright 2010, Ming-Yu Liu 00003 00004 All Rights Reserved 00005 00006 Permission to use, copy, modify, and distribute this software and 00007 its documentation for any non-commercial purpose is hereby granted 00008 without fee, provided that the above copyright notice appear in 00009 all copies and that both that copyright notice and this permission 00010 notice appear in supporting documentation, and that the name of 00011 the author not be used in advertising or publicity pertaining to 00012 distribution of the software without specific, written prior 00013 permission. 00014 00015 THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 00016 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00017 ANY PARTICULAR PURPOSE. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 00018 ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 00019 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 00020 AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING 00021 OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 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 }