Algorithms_in_C++  1.0.0
Set of algorithms implemented in C++.
SegmentIntersection Struct Reference

Public Member Functions

bool intersect (Point first_point, Point second_point, Point third_point, Point forth_point)
 
int direction (Point first_point, Point second_point, Point third_point)
 
bool on_segment (Point first_point, Point second_point, Point third_point)
 

Detailed Description

intersect returns true if segments of two line intersects and false if they do not. It calls the subroutines direction which computes the orientation.

Member Function Documentation

◆ direction()

int SegmentIntersection::direction ( Point  first_point,
Point  second_point,
Point  third_point 
)
inline

We will find direction of line here respect to @first_point. Here @second_point and @third_point is first and second points of the line respectively. we want a method to determine which way a given angle these three points turns. If returned number is negative, then the angle is counter-clockwise. That means the line is going to right to left. We will fount angle as clockwise if the method returns positive number.

64  {
65  return ((third_point.x - first_point.x) *
66  (second_point.y - first_point.y)) -
67  ((second_point.x - first_point.x) *
68  (third_point.y - first_point.y));
69  }

◆ on_segment()

bool SegmentIntersection::on_segment ( Point  first_point,
Point  second_point,
Point  third_point 
)
inline

This method determines whether a point known to be colinear with a segment lies on that segment.

76  {
77  if (std::min(first_point.x, second_point.x) <= third_point.x &&
78  third_point.x <= std::max(first_point.x, second_point.x) &&
79  std::min(first_point.y, second_point.y) <= third_point.y &&
80  third_point.y <= std::max(first_point.y, second_point.y))
81  return true;
82 
83  else
84  return false;
85  }
Here is the call graph for this function:

The documentation for this struct was generated from the following file:
Point::y
int y
Point respect to x coordinate.
Definition: line_segment_intersection.cpp:14
std::min
T min(T... args)
std::max
T max(T... args)