00001 /* 00002 This file is part of geometria. 00003 00004 geometria is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published 00006 by the Free Software Foundation; either version 2 of the License, 00007 or (at your option) any later version. 00008 00009 geometria is distributed in the hope that it will be useful, but 00010 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00011 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 00012 License for more details. 00013 00014 You should have received a copy of the GNU General Public 00015 License along with geometria; if not, write to the Free Software 00016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00017 00018 (c) Philipp Moritz, 2006 00019 */ 00020 00021 #include "lines_meet_algorithm.hpp" 00022 00023 lines_meet_algorithm::lines_meet_algorithm(boost::shared_ptr<geo_line> l, boost::shared_ptr<geo_line> m) 00024 : m_l(l), m_m(m) 00025 { 00026 m_l->register_observer(this); 00027 m_m->register_observer(this); 00028 } 00029 00030 lines_meet_algorithm::~lines_meet_algorithm(void) 00031 { 00032 m_l->unregister_observer(this); 00033 m_m->unregister_observer(this); 00034 } 00035 00036 00056 point lines_meet_algorithm::calculate() 00057 { 00058 double m_1 = m_l->get_line().get_m(); 00059 double t_1 = m_l->get_line().get_t(); 00060 00061 double m_2 = m_m->get_line().get_m(); 00062 double t_2 = m_m->get_line().get_t(); 00063 00064 double x = (t_2 - t_1)/(m_1 - m_2); 00065 double y = (m_1*t_2 - t_1*m_2)/(m_1 - m_2); 00066 return point(x, y); 00067 }