@@ -90,64 +90,6 @@ public static Vector3f calculateCenter(Vector3f a, Vector3f b, Vector3f c,
9090 return new Vector3f (x , y , z );
9191 }
9292
93- /**
94- * Calculates the intersection of a ray and circle.
95- *
96- * @param r the ray to test
97- * @param circle the circle to test
98- * @return the nearest intersection to the ray origin in positive direction
99- * of the ray, or null if there is no intersection
100- */
101- public static Vector2f calculateIntersection (Ray2D ray , Circle2D circle ) {
102- return calculateIntersection (ray , circle .getCenter (),
103- circle .getRadius ());
104- }
105-
106- /**
107- * Calculates the intersection of a ray and circle.
108- *
109- * @param ray the ray to test
110- * @param center the center of the circle to test
111- * @param radius the radius of the circle to test
112- * @return the nearest intersection to the ray origin in positive direction
113- * of the ray, or null if there is no intersection
114- */
115- public static Vector2f calculateIntersection (Ray2D ray , Vector2f center ,
116- float radius ) {
117- // Taken from:
118- // https://www.uninformativ.de/bin/RaytracingSchnitttests-76a577a-CC-BY.pdf
119- // Which point on the ray is the most nearest to the circle
120- float radius2 = radius * radius ;
121- float alpha = -ray .direction .dot (ray .origin .subtract (center ));
122- Vector2f q = ray .getPoint (alpha );
123-
124- // Distance to the circle center
125- q .subtractLocal (center );
126- float distToCenter2 = q .lengthSquared ();
127-
128- if (distToCenter2 > radius2 ) {
129- return null ;
130- }
131-
132- // Using pythagorean theorem to get intersections
133- float x = Mathf .sqrt (radius2 - distToCenter2 );
134-
135- // Which of the intersections is nearer to the ray origin in positive
136- // direction
137- float dist = 0.0f ;
138- if (alpha >= x ) {
139- dist = alpha - x ;
140- } else if (alpha + x > 0 ) {
141- dist = alpha + x ;
142- } else {
143- return null ;
144- }
145-
146- // The final intersection
147- q = ray .getPoint (dist );
148- return q ;
149- }
150-
15193 /**
15294 * Calculates the point on a circle.
15395 *
0 commit comments