Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/intern/math_geom.c
| Show First 20 Lines • Show All 547 Lines • ▼ Show 20 Lines | if (flip) { | ||||
| return min_ff(dist_a, dist_b); | return min_ff(dist_a, dist_b); | ||||
| } | } | ||||
| else { | else { | ||||
| return max_ff(dist_a, dist_b); | return max_ff(dist_a, dist_b); | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * return the distance squared of a point to a ray. | * Compute the squared distance of a point to a line (defined as ray). | ||||
| * \param ray_origin: A point on the line. | |||||
| * \param ray_direction: Normalized direction of the line. | |||||
| * \param co: Point to which the distance is to be calculated. | |||||
| */ | */ | ||||
| float dist_squared_to_ray_v3( | float dist_squared_to_ray_v3_normalized( | ||||
| const float ray_origin[3], const float ray_direction[3], | const float ray_origin[3], const float ray_direction[3], | ||||
| const float co[3], float *r_depth) | const float co[3]) | ||||
| { | { | ||||
| float dvec[3]; | float origin_to_co[3]; | ||||
| sub_v3_v3v3(dvec, co, ray_origin); | sub_v3_v3v3(origin_to_co, co, ray_origin); | ||||
| *r_depth = dot_v3v3(dvec, ray_direction); | |||||
| return len_squared_v3(dvec) - SQUARE(*r_depth); | float origin_to_proj[3]; | ||||
| project_v3_v3v3_normalized(origin_to_proj, origin_to_co, ray_direction); | |||||
| float co_projected_on_ray[3]; | |||||
| add_v3_v3v3(co_projected_on_ray, ray_origin, origin_to_proj); | |||||
| return len_squared_v3v3(co, co_projected_on_ray); | |||||
| } | } | ||||
| /** | /** | ||||
| * Find the closest point in a seg to a ray and return the distance squared. | * Find the closest point in a seg to a ray and return the distance squared. | ||||
| * \param r_point: Is the point on segment closest to ray (or to ray_origin if the ray and the segment are parallel). | * \param r_point: Is the point on segment closest to ray (or to ray_origin if the ray and the segment are parallel). | ||||
| * \param r_depth: the distance of r_point projection on ray to the ray_origin. | * \param r_depth: the distance of r_point projection on ray to the ray_origin. | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 4,662 Lines • Show Last 20 Lines | |||||