+ Vector surface = b - a;
+ Vector toPoint = other.point - a;
+
+ Scalar surfaceLength = surface.length();
+ surface.normalize();
+
+ Scalar projection = cml::dot(surface, toPoint);
+
+ if (projection < SCALAR(0.0) || projection > surfaceLength)
+ {
+ // try endpoints
+
+ if (other.intersect(a, hit))
+ {
+ hit.normal = -hit.normal;
+ hit.point = a;
+ return true;
+ }
+ else if (other.intersect(b, hit))
+ {
+ hit.normal = -hit.normal;
+ hit.point = b;
+ return true;
+ }
+
+ return false;
+ }
+
+ Vector point = a + surface * projection;
+ Vector normal = other.point - point;
+
+ Scalar distance = normal.length();
+
+ if (distance > other.radius) false; // not intersecting
+
+ normal.normalize();
+
+ hit.distance = other.radius - distance;
+ hit.point = point;
+ hit.normal = normal;
+
+ return true;
+ }
+
+
+ bool intersectRay(const Ray<2>& ray, Ray<2>::Contact& hit) const
+ {
+ Vector2 v1 = a - ray.point;
+ Scalar a1 = cml::signed_angle_2D(v1, b - ray.point);
+
+ //logWarning << "angle:::::::::: " << a1 << std::endl;
+
+ if (a1 == Constants::pi())
+ {
+ hit.distance = 5.4321;
+ return true;
+ }
+ else if (a1 == SCALAR(0.0))
+ {
+ hit.distance = 99999.0;
+ return true;
+ }
+
+ Scalar a2 = cml::signed_angle_2D(v1, ray.direction);
+
+ if (a2 < SCALAR(0.0) || a2 > a1) return false;
+
+ //hit.distance = 1.23456;
+ //hit.normal = Vector2(0.0, 0.0);
+
+ Vector2 n = (b - a).normalize();
+ Scalar z = cml::dot(ray.point - a, n);
+ Vector2 p = a + n * z;
+ hit.distance = (ray.point - p).length();
+ hit.normal = cml::perp(a - b);
+ return true;
+
+
+ /*