Commit: bc0ce658dd7808f894bef0842b2501abca9c84ed
Author: Campbell Barton
Date:   Mon May 23 21:31:22 2016 +1000
Branches: compositor-2016
https://developer.blender.org/rBbc0ce658dd7808f894bef0842b2501abca9c84ed

BLI_math: Add function to calculate circular cubic curve tangents

===================================================================

M       source/blender/blenlib/BLI_math_geom.h
M       source/blender/blenlib/intern/math_geom.c

===================================================================

diff --git a/source/blender/blenlib/BLI_math_geom.h 
b/source/blender/blenlib/BLI_math_geom.h
index 45edaca..54b824c9 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -470,6 +470,10 @@ MINLINE float shell_v2v2_normalized_to_dist(const float 
a[2], const float b[2]);
 MINLINE float shell_v3v3_mid_normalized_to_dist(const float a[3], const float 
b[3]);
 MINLINE float shell_v2v2_mid_normalized_to_dist(const float a[2], const float 
b[2]);
 
+/********************************* Cubic (Bezier) 
*******************************/
+
+float cubic_tangent_factor_circle_v3(const float tan_l[3], const float 
tan_r[3]);
+
 /**************************** Inline Definitions 
******************************/
 
 #if BLI_MATH_DO_INLINE
diff --git a/source/blender/blenlib/intern/math_geom.c 
b/source/blender/blenlib/intern/math_geom.c
index f80099b..370e8bb 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -4988,3 +4988,37 @@ int is_quad_flip_v3(const float v1[3], const float 
v2[3], const float v3[3], con
 
        return ret;
 }
+
+/**
+ * Return the value which the distance between points will need to be scaled 
by,
+ * to define a handle, given both points are on a perfect circle.
+ *
+ * Use when we want a bezier curve to match a circle as closely as possible.
+ *
+ * \note the return value will need to be divided by 0.75 for correct results.
+ */
+float cubic_tangent_factor_circle_v3(const float tan_l[3], const float 
tan_r[3])
+{
+       BLI_ASSERT_UNIT_V3(tan_l);
+       BLI_ASSERT_UNIT_V3(tan_r);
+
+       const float eps = 1e-7f;
+       const float tan_dot = dot_v3v3(tan_l, tan_r);
+       if (tan_dot > 1.0f - eps) {
+               /* no angle difference (use fallback, length wont make any 
difference) */
+               return (1.0f / 3.0f) * 0.75f;
+       }
+       else if (tan_dot < -1.0f + eps) {
+               /* parallele tangents (half-circle) */
+               return (1.0f / 2.0f);
+       }
+       else {
+               /* non-aligned tangents, calculate handle length */
+               const float angle = acosf(tan_dot) / 2.0f;
+
+               /* could also use 'angle_sin = len_vnvn(tan_l, tan_r, dims) / 
2.0' */
+               const float angle_sin = sinf(angle);
+               const float angle_cos = cosf(angle);
+               return ((1.0f - angle_cos) / (angle_sin * 2.0f)) / angle_sin;
+       }
+}

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to