Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/intern/math_geom.c
| Show First 20 Lines • Show All 3,242 Lines • ▼ Show 20 Lines | else { | ||||
| } | } | ||||
| if (tmax) { | if (tmax) { | ||||
| *tmax = hit_dist[1]; | *tmax = hit_dist[1]; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| /* find closest point to p on line through (l1, l2) and return lambda, | float closest_to_ray_v3(float r_close[3], | ||||
| * where (0 <= lambda <= 1) when cp is in the line segment (l1, l2) | const float p[3], | ||||
| const float ray_orig[3], | |||||
| const float ray_dir[3]) | |||||
| { | |||||
| float h[3], lambda; | |||||
| sub_v3_v3v3(h, p, ray_orig); | |||||
| lambda = dot_v3v3(ray_dir, h) / dot_v3v3(ray_dir, ray_dir); | |||||
| madd_v3_v3v3fl(r_close, ray_orig, ray_dir, lambda); | |||||
| return lambda; | |||||
| } | |||||
| /** | |||||
| * Find closest point to p on line through (l1, l2) and return lambda, | |||||
| * where (0 <= lambda <= 1) when cp is in the line segment (l1, l2). | |||||
| */ | */ | ||||
| float closest_to_line_v3(float r_close[3], const float p[3], const float l1[3], const float l2[3]) | float closest_to_line_v3(float r_close[3], const float p[3], const float l1[3], const float l2[3]) | ||||
| { | { | ||||
| float h[3], u[3], lambda; | float u[3]; | ||||
| sub_v3_v3v3(u, l2, l1); | sub_v3_v3v3(u, l2, l1); | ||||
| sub_v3_v3v3(h, p, l1); | return closest_to_ray_v3(r_close, p, l1, u); | ||||
| lambda = dot_v3v3(u, h) / dot_v3v3(u, u); | |||||
| r_close[0] = l1[0] + u[0] * lambda; | |||||
| r_close[1] = l1[1] + u[1] * lambda; | |||||
| r_close[2] = l1[2] + u[2] * lambda; | |||||
| return lambda; | |||||
| } | } | ||||
| float closest_to_line_v2(float r_close[2], const float p[2], const float l1[2], const float l2[2]) | float closest_to_line_v2(float r_close[2], const float p[2], const float l1[2], const float l2[2]) | ||||
| { | { | ||||
| float h[2], u[2], lambda; | float h[2], u[2], lambda; | ||||
| sub_v2_v2v2(u, l2, l1); | sub_v2_v2v2(u, l2, l1); | ||||
| sub_v2_v2v2(h, p, l1); | sub_v2_v2v2(h, p, l1); | ||||
| lambda = dot_v2v2(u, h) / dot_v2v2(u, u); | lambda = dot_v2v2(u, h) / dot_v2v2(u, u); | ||||
| ▲ Show 20 Lines • Show All 2,836 Lines • Show Last 20 Lines | |||||