{% else-1 %}
Если не нужна высокая точность,то сравнивать числители и знаменатели с нулём:
.. if(denom== 0)
{
if(nume_a == 0 && nume_b == 0)
Кусок из моей лабы по C++. Может кому-то пригодится *

                        
#include <math.h>
...

enum IntersectResult { PARALLEL , COINCIDENT ,NOT_INTERESECTING, INTERESECTING };

/** Определение координат точки пересечения двух отрезков.
Метод возврашает :
PARALLEL - если парралельны
COINCIDENT - если совпали (один из отрезков лежит на другом)
NOT_INTERESECTING - если непересеклись в отрезках
INTERESECTING - если пересеклись
в x и y передаётся координата пересечения

**/
int LineIntersection(
double begin_x_, double begin_y_,
double end_x_, double end_y_,
double other_line_begin_x_, double other_line_begin_y_,
double other_line_end_x_, double other_line_end_y_,
double &x, double &y
){


double denom = ((other_line_end_y_ - other_line_begin_y_)*(end_x_ - begin_x_)) -
((other_line_end_x_ - other_line_begin_x_)*(end_y_ - begin_y_));

double nume_a = ((other_line_end_x_ - other_line_begin_x_)*(begin_y_ - other_line_begin_y_)) -
((other_line_end_y_ - other_line_begin_y_)*(begin_x_ - other_line_begin_x_));

double nume_b = ((end_x_ - begin_x_)*(begin_y_ - other_line_begin_y_)) -
((end_y_ - begin_y_)*(begin_x_ - other_line_begin_x_));
if(abs(denom) <= 0.00001)
{
if(abs(nume_a) <= 0.00001 && abs(nume_b) <= 0.00001)
{
return COINCIDENT;
}
return PARALLEL;
}

double ua = nume_a / denom;
double ub = nume_b / denom;

if(ua >= 0.0 && ua <= 1.0 && ub >= 0.0 && ub <= 1.0)
{
// получаем точку пересечения
x = begin_x_ + ua*(end_x_ - begin_x_);
y = begin_y_ + ua*(end_y_ - begin_y_);

return INTERESECTING;
}

return NOT_INTERESECTING;
}
0 13 0
0

Нет фото
• 19 янв 2015, 20:19


знаменатели с нулём
*