[Bf-extensions-cvs] [f58fe4df] master: PDT: Further Expansion of Tangent System

Alan Odom noreply at git.blender.org
Sat Mar 28 18:59:43 CET 2020


Commit: f58fe4df0da454bc69b70589d1111aefaa36a182
Author: Alan Odom
Date:   Sun Feb 16 19:57:38 2020 +0000
Branches: master
https://developer.blender.org/rBAf58fe4df0da454bc69b70589d1111aefaa36a182

PDT: Further Expansion of Tangent System

This is still WIP.

Further expand options to work in any plane and from selected vertices.
DocStrings Added. Code refactored.

Further testing is still required before this can be released for general use.

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

M	pdt_tangent.py
M	precision_drawing_tools/__init__.py
M	precision_drawing_tools/pdt_exception.py
M	precision_drawing_tools/pdt_functions.py
M	precision_drawing_tools/pdt_menus.py
M	precision_drawing_tools/pdt_msg_strings.py

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

diff --git a/pdt_tangent.py b/pdt_tangent.py
index 1f2a7ab9..a00be313 100644
--- a/pdt_tangent.py
+++ b/pdt_tangent.py
@@ -23,96 +23,371 @@
 #
 import bpy
 import bmesh
-from math import sqrt
+from math import sqrt, floor, asin, sin, cos, pi
 from mathutils import Vector
 from bpy.types import Operator
 
 from .pdt_functions import (
     oops,
     arc_centre,
+    set_mode,
+    view_coords,
+    view_coords_i,
 )
 
 from .pdt_msg_strings import (
     PDT_OBJ_MODE_ERROR,
     PDT_ERR_NO_ACT_OBJ,
     PDT_ERR_SEL_3_VERTS,
+    PDT_ERR_SEL_1_VERT,
+    PDT_ERR_BADDISTANCE,
+    PDT_ERR_MATHSERROR,
+    PDT_ERR_SAMERADII,
+    PDT_ERR_VERT_MODE,
 )
 
 from . import pdt_exception
 PDT_ObjectModeError = pdt_exception.ObjectModeError
-PDT_NoObjectError = pdt_exception.NoObjectError
 PDT_SelectionError = pdt_exception.SelectionError
 
 
-def get_tangent_intersect_outer(xloc_0, yloc_0, xloc_1, yloc_1, radius_0, radius_1):
-    xloc_p = ((xloc_1 * radius_0) - (xloc_0 * radius_1)) / (radius_0 - radius_1)
-    yloc_p = ((yloc_1 * radius_0) - (yloc_0 * radius_1)) / (radius_0 - radius_1)
+def get_tangent_intersect_outer(hloc_0, vloc_0, hloc_1, vloc_1, radius_0, radius_1):
+    """Return Location in 2 Dimensions of the Intersect Point for Outer Tangents.
 
-    return xloc_p, yloc_p
+    Args:
+        hloc_0: Horizontal Coordinate of Centre of First Arc
+        vloc_0: Vertical Coordinate of Centre of First Arc
+        hloc_1: Horizontal Coordinate of Centre of Second Arc
+        vloc_1: Vertical Coordinate of Centre of Second Arc
+        radius_0: Radius of First Arc
+        radius_1: Radius of Second Arc
 
+    Returns:
+        hloc_p: Horizontal Coordinate of Centre of Intersection
+        vloc_p: Vertical Coordinate of Centre of Intersection.
+    """
 
-def get_tangent_intersect_inner(xloc_0, yloc_0, xloc_1, yloc_1, radius_0, radius_1):
-    xloc_p = ((xloc_1 * radius_0) + (xloc_0 * radius_1)) / (radius_0 + radius_1)
-    yloc_p = ((yloc_1 * radius_0) + (yloc_0 * radius_1)) / (radius_0 + radius_1)
+    hloc_p = ((hloc_1 * radius_0) - (hloc_0 * radius_1)) / (radius_0 - radius_1)
+    vloc_p = ((vloc_1 * radius_0) - (vloc_0 * radius_1)) / (radius_0 - radius_1)
 
-    return xloc_p, yloc_p
+    return hloc_p, vloc_p
 
 
-def get_tangent_points(xloc_0, yloc_0, radius_0, xloc_p, yloc_p):
-    numerator = (radius_0 ** 2 * (xloc_p - xloc_0)) + (
+def get_tangent_intersect_inner(hloc_0, vloc_0, hloc_1, vloc_1, radius_0, radius_1):
+    """Return Location in 2 Dimensions of the Intersect Point for Inner Tangents.
+
+    Args:
+        hloc_0: Horizontal Coordinate of Centre of First Arc
+        vloc_0: Vertical Coordinate of Centre of First Arc
+        hloc_1: Horizontal Coordinate of Centre of Second Arc
+        vloc_1: Vertical Coordinate of Centre of Second Arc
+        radius_0: Radius of First Arc
+        radius_1: Radius of Second Arc
+
+    Returns:
+        hloc_p: Horizontal Coordinate of Centre of Intersection
+        vloc_p: Vertical Coordinate of Centre of Intersection.
+    """
+
+    hloc_p = ((hloc_1 * radius_0) + (hloc_0 * radius_1)) / (radius_0 + radius_1)
+    vloc_p = ((vloc_1 * radius_0) + (vloc_0 * radius_1)) / (radius_0 + radius_1)
+
+    return hloc_p, vloc_p
+
+
+def get_tangent_points(context, hloc_0, vloc_0, radius_0, hloc_p, vloc_p):
+    """Return Location in 2 Dimensions of the Tangent Points.
+
+    Args:
+        context: Blender bpy.context instance
+        hloc_0: Horizontal Coordinate of Centre of First Arc
+        vloc_0: Vertical Coordinate of Centre of First Arc
+        radius_0: Radius of First Arc
+        hloc_p: Horizontal Coordinate of Intersection
+        vloc_p: Vertical Coordinate of Intersection
+
+    Returns:
+        hloc_t1: Horizontal Location of First Tangent Point
+        hloc_t2: Horizontal Location of Second Tangent Point
+        vloc_t1: Vertical Location of First Tangent Point
+        vloc_t2: Vertical Location of Second Tangent Point
+    """
+    numerator = (radius_0 ** 2 * (hloc_p - hloc_0)) + (
         radius_0
-        * (yloc_p - yloc_0)
-        * sqrt((xloc_p - xloc_0) ** 2 + (yloc_p - yloc_0) ** 2 - radius_0 ** 2)
+        * (vloc_p - vloc_0)
+        * sqrt((hloc_p - hloc_0) ** 2 + (vloc_p - vloc_0) ** 2 - radius_0 ** 2)
     )
-    denominator = (xloc_p - xloc_0) ** 2 + (yloc_p - yloc_0) ** 2
-    xloc_t1 = round((numerator / denominator) + xloc_0, 5)
+    denominator = (hloc_p - hloc_0) ** 2 + (vloc_p - vloc_0) ** 2
+    hloc_t1 = round((numerator / denominator) + hloc_0, 5)
 
-    numerator = (radius_0 ** 2 * (xloc_p - xloc_0)) - (
+    numerator = (radius_0 ** 2 * (hloc_p - hloc_0)) - (
         radius_0
-        * (yloc_p - yloc_0)
-        * sqrt((xloc_p - xloc_0) ** 2 + (yloc_p - yloc_0) ** 2 - radius_0 ** 2)
+        * (vloc_p - vloc_0)
+        * sqrt((hloc_p - hloc_0) ** 2 + (vloc_p - vloc_0) ** 2 - radius_0 ** 2)
     )
-    denominator = (xloc_p - xloc_0) ** 2 + (yloc_p - yloc_0) ** 2
-    xloc_t2 = round((numerator / denominator) + xloc_0, 5)
+    denominator = (hloc_p - hloc_0) ** 2 + (vloc_p - vloc_0) ** 2
+    hloc_t2 = round((numerator / denominator) + hloc_0, 5)
 
     # Get Y values
-    numerator = (radius_0 ** 2 * (yloc_p - yloc_0)) - (
+    numerator = (radius_0 ** 2 * (vloc_p - vloc_0)) - (
         radius_0
-        * (xloc_p - xloc_0)
-        * sqrt((xloc_p - xloc_0) ** 2 + (yloc_p - yloc_0) ** 2 - radius_0 ** 2)
+        * (hloc_p - hloc_0)
+        * sqrt((hloc_p - hloc_0) ** 2 + (vloc_p - vloc_0) ** 2 - radius_0 ** 2)
     )
-    denominator = (xloc_p - xloc_0) ** 2 + (yloc_p - yloc_0) ** 2
-    yloc_t1 = round((numerator / denominator) + yloc_0, 5)
+    denominator = (hloc_p - hloc_0) ** 2 + (vloc_p - vloc_0) ** 2
+    vloc_t1 = round((numerator / denominator) + vloc_0, 5)
 
-    numerator = (radius_0 ** 2 * (yloc_p - yloc_0)) + (
+    numerator = (radius_0 ** 2 * (vloc_p - vloc_0)) + (
         radius_0
-        * (xloc_p - xloc_0)
-        * sqrt((xloc_p - xloc_0) ** 2 + (yloc_p - yloc_0) ** 2 - radius_0 ** 2)
+        * (hloc_p - hloc_0)
+        * sqrt((hloc_p - hloc_0) ** 2 + (vloc_p - vloc_0) ** 2 - radius_0 ** 2)
     )
-    denominator = (xloc_p - xloc_0) ** 2 + (yloc_p - yloc_0) ** 2
-    yloc_t2 = round((numerator / denominator) + yloc_0, 5)
-
-    return xloc_t1, xloc_t2, yloc_t1, yloc_t2
-
-
-def draw_tangents(
-    xloc_to1, xloc_to2, yloc_to1, yloc_to2, xloc_to3, xloc_to4, yloc_to3, yloc_to4, bm, obj, obj_loc
-):
-    tangent_vector_o1 = Vector((xloc_to1, 0, yloc_to1))
-    tangent_vertex_o1 = bm.verts.new(tangent_vector_o1 - obj_loc)
-    tangent_vector_o2 = Vector((xloc_to2, 0, yloc_to2))
-    tangent_vertex_o2 = bm.verts.new(tangent_vector_o2 - obj_loc)
-    tangent_vector_o3 = Vector((xloc_to3, 0, yloc_to3))
-    tangent_vertex_o3 = bm.verts.new(tangent_vector_o3 - obj_loc)
-    tangent_vector_o4 = Vector((xloc_to4, 0, yloc_to4))
-    tangent_vertex_o4 = bm.verts.new(tangent_vector_o4 - obj_loc)
-    # Add Edges
-    bm.edges.new([tangent_vertex_o1, tangent_vertex_o3])
-    bm.edges.new([tangent_vertex_o2, tangent_vertex_o4])
+    denominator = (hloc_p - hloc_0) ** 2 + (vloc_p - vloc_0) ** 2
+    vloc_t2 = round((numerator / denominator) + vloc_0, 5)
+
+    return hloc_t1, hloc_t2, vloc_t1, vloc_t2
+
+
+def make_vectors(coords, a1, a2, a3, pg):
+    """Return Vectors of the Tangent Points.
+
+    Args:
+        coords: A List of Coordinates in 2D space of the tangent points
+                & a third dimension for the vectors
+        a1: Index of horizontal axis
+        a2: Index of vertical axis
+        a3: Index of depth axis
+        pg: PDT Parameters Group - our variables
+
+    Returns:
+        tangent_vector_o1: Location of First Tangent Point
+        tangent_vector_o2: Location of Second Tangent Point
+        tangent_vector_o3: Location of First Tangent Point
+        tangent_vector_o4: Location of Second Tangent Point
+    """
+
+    tangent_vector_o1 = Vector((0, 0, 0))
+    tangent_vector_o1[a1] = coords[0]
+    tangent_vector_o1[a2] = coords[1]
+    tangent_vector_o1[a3] = coords[8]
+    tangent_vector_o2 = Vector((0, 0, 0))
+    tangent_vector_o2[a1] = coords[2]
+    tangent_vector_o2[a2] = coords[3]
+    tangent_vector_o2[a3] = coords[8]
+    tangent_vector_o3 = Vector((0, 0, 0))
+    tangent_vector_o3[a1] = coords[4]
+    tangent_vector_o3[a2] = coords[5]
+    tangent_vector_o3[a3] = coords[8]
+    tangent_vector_o4 = Vector((0, 0, 0))
+    tangent_vector_o4[a1] = coords[6]
+    tangent_vector_o4[a2] = coords[7]
+    tangent_vector_o4[a3] = coords[8]
+
+    if pg.plane == "LO":
+        tangent_vector_o1 = view_coords(tangent_vector_o1[a1], tangent_vector_o1[a2],
+        tangent_vector_o1[a3])
+        tangent_vector_o2 = view_coords(tangent_vector_o2[a1], tangent_vector_o2[a2],
+        tangent_vector_o2[a3])
+        tangent_vector_o3 = view_coords(tangent_vector_o3[a1], tangent_vector_o3[a2],
+        tangent_vector_o3[a3])
+        tangent_vector_o4 = view_coords(tangent_vector_o4[a1], tangent_vector_o4[a2],
+        tangent_vector_o4[a3])
+
+    return ((tangent_vector_o1, tangent_vector_o2, tangent_vector_o3, tangent_vector_o4))
+
+def tangent_setup(context, pg, plane, obj_data, centre_0, centre_1, centre_2, radius_0, radius_1):
+    # Depth is a3
+    a1, a2, a3 = set_mode(plane)
+    if plane == "LO":
+        centre_0 = view_coords_i(centre_0[a1], centre_0[a2], centre_0[a3])
+        centre_1 = view_coords_i(centre_1[a1], centre_1[a2], centre_1[a3])
+        centre_2 = view_coords_i(centre_2[a1], centre_2[a2], centre_2[a3])
+    if pg.tangent_from_point:
+        vector_difference = centre_2 - centre_0
+        distance = sqrt(vector_difference[a1] ** 2 + vector_difference[a2] ** 2)
+    else:
+        vector_difference = centre_1 - centre_0
+        distance = sqrt(vector_difference[a1] ** 2 + vector_difference[a2] ** 2)
+    if distance > radius_0 + radius_1 and not pg.tangent_from_point:
+        mode = "inner"
+    elif distance > radius_0 and distance > radius_1 and not pg.tangent_from_point:
+        mode = "outer"
+    elif distance > radius_1 and pg.tangent_from_point:
+        mode = "point"
+    else:
+        # Cannot execute, centres are too close.
+        pg.error = f"{PDT_ERR_BAD

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list