30 m_valid_parameters =
false;
38 m_valid_parameters =
false;
50 m_valid_parameters = other.m_valid_parameters;
67 m_valid_parameters = a_line.m_valid_parameters;
88 int a2dLine::ActionOnTable1( R_PointStatus Result_beginPoint, R_PointStatus Result_endPoint )
const
92 ( Result_beginPoint == R_IN_AREA )
94 ( Result_endPoint == R_IN_AREA )
100 ( Result_beginPoint == R_LEFT_SIDE )
102 ( Result_endPoint == R_LEFT_SIDE )
106 ( Result_beginPoint == R_RIGHT_SIDE )
108 ( Result_endPoint == R_RIGHT_SIDE )
115 ( Result_beginPoint == R_LEFT_SIDE )
118 ( Result_endPoint == R_RIGHT_SIDE )
120 ( Result_endPoint == R_ON_AREA )
125 ( Result_beginPoint == R_RIGHT_SIDE )
128 ( Result_endPoint == R_LEFT_SIDE )
130 ( Result_endPoint == R_ON_AREA )
135 ( Result_beginPoint == R_ON_AREA )
138 ( Result_endPoint == R_LEFT_SIDE )
140 ( Result_endPoint == R_RIGHT_SIDE )
142 ( Result_endPoint == R_ON_AREA )
150 ( Result_beginPoint == R_LEFT_SIDE )
152 ( Result_beginPoint == R_RIGHT_SIDE )
155 ( Result_endPoint == R_IN_AREA )
160 ( Result_beginPoint == R_IN_AREA )
163 ( Result_endPoint == R_LEFT_SIDE )
165 ( Result_endPoint == R_RIGHT_SIDE )
171 ( Result_beginPoint == R_IN_AREA )
173 ( Result_endPoint == R_ON_AREA )
178 ( Result_beginPoint == R_ON_AREA )
180 ( Result_endPoint == R_IN_AREA )
204 int a2dLine::ActionOnTable2( R_PointStatus Result_beginPoint, R_PointStatus Result_endPoint )
const
208 ( Result_beginPoint == R_IN_AREA )
210 ( Result_endPoint == R_IN_AREA )
216 ( Result_beginPoint == R_LEFT_SIDE )
219 ( Result_endPoint == R_LEFT_SIDE )
221 ( Result_endPoint == R_ON_AREA )
226 ( Result_beginPoint == R_RIGHT_SIDE )
229 ( Result_endPoint == R_RIGHT_SIDE )
231 ( Result_endPoint == R_ON_AREA )
236 ( Result_beginPoint == R_ON_AREA )
239 ( Result_endPoint == R_LEFT_SIDE )
241 ( Result_endPoint == R_RIGHT_SIDE )
243 ( Result_endPoint == R_ON_AREA )
251 ( Result_beginPoint == R_LEFT_SIDE )
253 ( Result_endPoint == R_RIGHT_SIDE )
257 ( Result_beginPoint == R_RIGHT_SIDE )
259 ( Result_endPoint == R_LEFT_SIDE )
266 ( Result_beginPoint == R_LEFT_SIDE )
268 ( Result_beginPoint == R_RIGHT_SIDE )
270 ( Result_beginPoint == R_ON_AREA )
273 ( Result_endPoint == R_IN_AREA )
278 ( Result_beginPoint == R_IN_AREA )
281 ( Result_endPoint == R_LEFT_SIDE )
283 ( Result_endPoint == R_RIGHT_SIDE )
285 ( Result_endPoint == R_ON_AREA )
296 assert( m_valid_parameters );
298 return -( m_AA * X + m_CC ) / m_BB;
306 assert( m_valid_parameters );
311 a_point.m_y = a_point.m_y + ( distance * -m_BB );
312 a_point.m_x = a_point.m_x - ( distance * m_AA );
317 assert( m_valid_parameters );
322 a_point.m_y = m_a.m_y + ( distance * m_AA );
323 a_point.m_x = m_a.m_x + ( distance * -m_BB );
327 a_point.m_y = m_b.m_y + ( distance * m_AA );
328 a_point.m_x = m_b.m_x + ( distance * -m_BB );
335 assert( m_valid_parameters );
340 begin.m_y = a_point.m_y + ( distance * -m_BB );
341 begin.m_x = a_point.m_x - ( distance * m_AA );
343 end.m_y = a_point.m_y - ( distance * -m_BB );
344 end.m_x = a_point.m_x + ( distance * m_AA );
346 return new a2dLine( begin, end );
351 return sqrt(
wxSqr( m_b.m_y - m_a.m_y ) +
wxSqr( m_a.m_x - m_b.m_x ) );
358 if ( !m_valid_parameters )
372 m_AA = ( m_b.m_y - m_a.m_y );
373 m_BB = ( m_a.m_x - m_b.m_x );
377 length = sqrt( m_AA * m_AA + m_BB * m_BB );
379 assert( length != 0 );
381 m_AA = ( m_AA / length );
382 m_BB = ( m_BB / length );
384 m_CC = -( ( m_AA * m_a.m_x ) + ( m_a.m_y * m_BB ) );
386 m_valid_parameters =
true;
407 int Take_Action1, Take_Action2;
408 bool Total_Result =
false;
409 R_PointStatus Result_beginPoint, Result_endPoint;
411 Result_beginPoint =
PointInLine( lijn.m_a, distance, Marge );
412 Result_endPoint =
PointInLine( lijn.m_b, distance, Marge );
413 Take_Action1 = ActionOnTable1( Result_beginPoint, Result_endPoint );
414 switch ( Take_Action1 )
416 case 0: Total_Result = false ;
break;
419 Result_beginPoint = lijn.
PointInLine( m_a, distance, Marge );
420 Result_endPoint = lijn.
PointInLine( m_b, distance, Marge );
421 Take_Action2 = ActionOnTable2( Result_beginPoint, Result_endPoint );
422 switch ( Take_Action2 )
424 case 0: Total_Result =
false;
break;
425 case 1:
case 2:
case 3:
case 4: Total_Result =
true;
break;
429 case 2:
case 3:
case 4:
case 5:
case 6: Total_Result =
true;
break;
459 R_PointStatus Result_beginPoint, Result_endPoint;
460 int Take_Action1, Take_Action2, Number_of_Crossings = 0;
462 Result_beginPoint =
PointInLine( lijn.m_a, distance, Marge );
463 Result_endPoint =
PointInLine( lijn.m_b, distance, Marge );
465 Take_Action1 = ActionOnTable1( Result_beginPoint, Result_endPoint );
475 switch ( Take_Action1 )
477 case 2:
case 6: c1 = lijn.m_b;
478 Number_of_Crossings = 1;
480 case 3:
case 5: c1 = lijn.m_a;
481 Number_of_Crossings = 1;
483 case 4: c1 = lijn.m_a;
485 Number_of_Crossings = 2;
495 switch ( Take_Action1 )
497 case 1:
case 5:
case 6:
499 Result_beginPoint = lijn.
PointInLine( m_a, distance, Marge );
500 Result_endPoint = lijn.
PointInLine( m_b, distance, Marge );
501 Take_Action2 = ActionOnTable2( Result_beginPoint, Result_endPoint );
508 switch ( Take_Action2 )
514 double X, Y, Denominator;
515 assert( m_valid_parameters );
516 Denominator = ( m_AA * lijn.m_BB ) - ( lijn.m_AA * m_BB );
518 assert( Denominator != 0.0 );
520 X = ( ( m_BB * lijn.m_CC ) - ( lijn.m_BB * m_CC ) ) / Denominator;
521 Y = ( ( lijn.m_AA * m_CC ) - ( m_AA * lijn.m_CC ) ) / Denominator;
526 Number_of_Crossings++;
529 Number_of_Crossings++;
532 Number_of_Crossings++;
536 Number_of_Crossings = 2;
544 return Number_of_Crossings;
564 int Result_ofm_BBox =
false;
565 R_PointStatus Result_of_Online;
568 if ( a_Point == m_a || a_Point == m_b )
575 a_Point.m_x >= ( m_a.m_x - Marge ) && a_Point.m_x <= ( m_a.m_x + Marge ) &&
576 a_Point.m_y >= ( m_a.m_y - Marge ) && a_Point.m_y <= ( m_a.m_y + Marge )
584 double xmin = wxMin( m_a.m_x, m_b.m_x );
585 double xmax = wxMax( m_a.m_x, m_b.m_x );
586 double ymin = wxMin( m_a.m_y, m_b.m_y );
587 double ymax = wxMax( m_a.m_y, m_b.m_y );
589 if ( a_Point.m_x >= ( xmin - Marge ) && a_Point.m_x <= ( xmax + Marge ) &&
590 a_Point.m_y >= ( ymin - Marge ) && a_Point.m_y <= ( ymax + Marge ) )
591 Result_ofm_BBox =
true;
594 Result_of_Online =
PointOnLine( a_Point, Distance, Marge );
597 if ( ( Result_ofm_BBox ) && ( Result_of_Online == R_ON_AREA ) )
600 return Result_of_Online;
618 assert( m_a != m_b );
621 if ( a_Point == m_a || a_Point == m_b )
624 assert( m_valid_parameters );
626 Distance = ( m_AA * a_Point.m_x ) + ( m_BB * a_Point.m_y ) + m_CC;
628 if ( Distance < -Marge )
632 if ( Distance > Marge )
641 double dx12 = double( m_b.m_x ) - double( m_a.m_x );
642 double dy12 = double( m_b.m_y ) - double( m_a.m_y );
644 double dx1p = double( p.m_x ) - double( m_a.m_x );
645 double dy1p = double( p.m_y ) - double( m_a.m_y );
647 double length = dx12 * dx12 + dy12 * dy12;
648 double projection = dx12 * dx1p + dy12 * dy1p;
653 projection /= length;
654 return a2dPoint2D( m_a.m_x + projection * dx12, m_a.m_y + projection * dy12 );
659 double dx12 = double( m_b.m_x ) - double( m_a.m_x );
660 double dy12 = double( m_b.m_y ) - double( m_a.m_y );
662 double dx1p = double( p.m_x ) - double( m_a.m_x );
663 double dy1p = double( p.m_y ) - double( m_a.m_y );
665 double length = dx12 * dx12 + dy12 * dy12;
666 double projection = dx12 * dx1p + dy12 * dy1p;
668 if( projection <= 0 || length == 0 )
671 if( nearest ) * nearest = m_a;
672 return sqrt( dx1p * dx1p + dy1p * dy1p );
674 else if( projection >= length )
677 if( nearest ) * nearest = m_b;
678 double dx2p = double( p.m_x ) - double( m_b.m_x );
679 double dy2p = double( p.m_y ) - double( m_b.m_y );
680 return sqrt( dx2p * dx2p + dy2p * dy2p );
698 projection /= length;
699 if( nearest ) * nearest =
a2dPoint2D( m_a.m_x + projection * dx12, m_a.m_y + projection * dy12 );
701 dx1p -= projection * dx12;
702 dy1p -= projection * dy12;
703 return sqrt( dx1p * dx1p + dy1p * dy1p );
709 double dx12 = double( m_b.m_x ) - double( m_a.m_x );
710 double dy12 = double( m_b.m_y ) - double( m_a.m_y );
712 double dx1p = double( p.m_x ) - double( m_a.m_x );
713 double dy1p = double( p.m_y ) - double( m_a.m_y );
715 if( dx12 == 0 && dy12 == 0 )
721 else if( fabs( dx12 ) < fabs( dy12 ) )
724 if( p.m_y < wxMin( m_a.m_y, m_b.m_y ) || p.m_y > wxMax( m_a.m_y, m_b.m_y ) )
733 double x = dy1p * dx12 / dy12 + m_a.m_x;
739 return fabs( p.m_x - x );
745 if( p.m_x < wxMin( m_a.m_x, m_b.m_x ) || p.m_x > wxMax( m_a.m_x, m_b.m_x ) )
754 double y = dx1p * dy12 / dx12 + m_a.m_y;
760 return fabs( p.m_y - y );
776 a2dLine offs_currentline( offs_begin, offs_end );
780 a2dLine offs_nextline( offs_bgn_next, offs_end_next );
784 offs_currentline.
Intersect( offs_nextline, offsetpoint );
799 if ( two.m_a == two.m_b )
814 if ( uitp == R_LEFT_SIDE )
816 if ( uitp == R_RIGHT_SIDE )
826 assert( m_valid_parameters );
827 assert( lijn.m_valid_parameters );
829 double X, Y, Denominator;
830 Denominator = ( m_AA * lijn.m_BB ) - ( lijn.m_AA * m_BB );
832 if ( Denominator == 0.0 )
835 X = ( ( m_BB * lijn.m_CC ) - ( lijn.m_BB * m_CC ) ) / Denominator;
836 Y = ( ( lijn.m_AA * m_CC ) - ( m_AA * lijn.m_CC ) ) / Denominator;
wxPoint2DDouble a2dPoint2D
this to define if coordinate numbers are integer or doubles
a2dPoint2D DistancePoint(double distance, bool begin) const
calculate point on line at distance from the begin or end of line
double PointDistance(const a2dPoint2D &p, a2dPoint2D *nearest) const
Calculate the distance of a point from the line. Works even if l==0.
a2dPoint2D GetEndPoint() const
Get the endpoint from a a2dLine.
double Calculate_Y(double X) const
Caclulate Y if X is known.
R_PointStatus PointInLine(const a2dPoint2D &a_Point, double &Distance, double Marge) const
For a non-infinite a2dLine.
a2dLine * CreatePerpendicularLineAt(const a2dPoint2D &a_point) const
create a line through a_point and which is pperpendicular to this
R_PointStatus PointOnLine(const a2dPoint2D &a_Point, double &Distance, double Marge) const
For an infinite a2dLine.
OUTPRODUCT OutProduct(const a2dLine &two, double accur) const
outproduct of two wxLines
void Virtual_Point(a2dPoint2D &a_point, double distance) const
calculate point Perpendicula at distance from the line, through given point
a2dLine & operator=(const a2dLine &other)
void CalculateLineParameters()
Calculate the parameters if invalid.
double wxSqr(double x)
good replacement for pow(x,2)
a2dPoint2D ProjectedPoint(const a2dPoint2D &p) const
return point after projecting p to this line.
double PointDistanceOrhto(const a2dPoint2D &p, a2dPoint2D *nearest) const
Calculate the orthogonal distance of a point from the line. Works even if l==0.
a2dPoint2D GetBeginPoint() const
Get the beginpoint from a a2dLine.
void OffsetContour(const a2dLine &nextline, double factor, a2dPoint2D &offsetpoint) const
Calculate point for a contour at a given distance.
double GetLength() const
return length of vector
bool CheckIntersect(a2dLine &line, double Marge) const
Check if two wxLines intersects.
a2dLine(double x1=0, double y1=0, double x2=0, double y2=0)
create a line with given end and begin point
basic 2 point line class for intersection and contouring routines.
int Intersect(a2dLine &line, a2dPoint2D &bp, a2dPoint2D &ep, double Marge) const
Intersects two wxLines.