Skip to Content.
Sympa Menu

cgal-discuss - Segment has_on() question

Subject: CGAL users discussion list

List archive

Segment has_on() question


Chronological Thread 
  • From:
  • To:
  • Subject: Segment has_on() question
  • Date: Sat, 9 Feb 2008 18:24:10 +0100

Hi Everyone,

I am quite a newbie to CGAL.

I was trying to run a simple example, but I was not getting the expected
output. I am trying to find if a point is on a line segment. My code is as
follows

typedef CGAL::Cartesian_d<double> K;
typedef K::Segment_d CGAL_Segment;

double* arr = new double[2];
arr[0] = 2.0;
arr[1] = 4.0;
CGAL_Point p1(2, arr, arr+2);

arr[0] = 5.0;
arr[1] = 8.0;
CGAL_Point p2(2, arr, arr+2);
CGAL_Segment s(p1, p2);
cout << "Segment = " << s << endl;

vector<double> vec;
double len = std::sqrt(v.squared_length());
for(int i=0; i < v.dimension(); i++) {
vec.push_back(v[i]/len);
}
CGAL_Vector unit_vec(v.dimension(), vec.begin(), vec.end()); // Unit vector.

cout << "Is p5 on segment s = " << s.has_on(p1 + unit_vec) << endl;

It is easy to see that the point p1+unit_vec ([2.6, 4.8] in this case) is on
the segment. Why does has_on() say that the point is not on the segment?

Thank you in anticipation.
Regards,
Vineet




Archive powered by MHonArc 2.6.16.

Top of Page