Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solely use numpy for trig functions. #106

Open
wants to merge 1 commit into
base: refactor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/clusters/carbonfet.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import json
import os
import numpy as np
from dataclasses_json import dataclass_json
from dataclasses import dataclass
from dataclasses_json import dataclass_json
from dataclasses import dataclass
import clusters.cluster_abc as ca
from dactyl_manuform import rad2deg, pi
from typing import Any, Sequence

def debugprint(data):
Expand Down Expand Up @@ -81,7 +79,7 @@ def thumb_15x_layout(self, shape, cap=False, plate=True):

def thumbcaps(self):
t1 = self.thumb_1x_layout(self.pl.sa_cap(1))
t15 = self.thumb_15x_layout(self.g.rotate(self.pl.sa_cap(1.5), [0, 0, rad2deg(pi / 2)]))
t15 = self.thumb_15x_layout(self.g.rotate(self.pl.sa_cap(1.5), [0, 0, 90]))
return t1.add(t15)

def thumb(self):
Expand Down
1 change: 0 additions & 1 deletion src/clusters/cluster_abc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import os
import numpy as np
from dataclasses_json import dataclass_json
from dataclasses import dataclass
from abc import ABC
Expand Down
2 changes: 0 additions & 2 deletions src/clusters/default.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import json
import os
import numpy as np
from dataclasses_json import dataclass_json
from dataclasses import dataclass
import clusters.cluster_abc as ca
from dactyl_manuform import rad2deg, pi
from typing import Any, Sequence

def debugprint(data):
Expand Down
4 changes: 1 addition & 3 deletions src/clusters/mini.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
from dataclasses_json import dataclass_json
from dataclasses import dataclass
import clusters.cluster_abc as ca
from dactyl_manuform import rad2deg, pi
from typing import Any, Sequence
import numpy as np

def debugprint(data):
pass
Expand Down Expand Up @@ -98,7 +96,7 @@ def thumb_15x_layout(self, shape, cap=False, plate=True):

def thumbcaps(self):
t1 = self.thumb_1x_layout(self.pl.sa_cap(1))
t15 = self.thumb_15x_layout(self.g.rotate(self.pl.sa_cap(1), [0, 0, rad2deg(pi / 2)]))
t15 = self.thumb_15x_layout(self.g.rotate(self.pl.sa_cap(1), [0, 0, 90]))
return t1.add(t15)

def thumb(self):
Expand Down
2 changes: 0 additions & 2 deletions src/clusters/minidox.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from clusters.default import DefaultCluster
import os
import json
import numpy as np
from dataclasses_json import dataclass_json
from dataclasses import dataclass
import clusters.cluster_abc as ca
from dactyl_manuform import rad2deg, pi
from typing import Any, Sequence

def debugprint(data):
Expand Down
4 changes: 1 addition & 3 deletions src/clusters/trackball_cj.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import json
import os
import math
import numpy as np
from dataclasses_json import dataclass_json
from dataclasses import dataclass
import clusters.trackball_cluster_abc as ca
from dactyl_manuform import rad2deg, pi
from typing import Any, Sequence

def debugprint(data):
Expand Down Expand Up @@ -69,7 +67,7 @@ def oct_corner(self, i, diameter, shape):
i = (i + 1) % 8

r = radius
m = radius * math.tan(math.pi / 8)
m = radius * np.tan(np.pi / 8)

points_x = [m, r, r, m, -m, -r, -r, -m]
points_y = [r, m, -m, -r, -r, -m, m, r]
Expand Down
2 changes: 0 additions & 2 deletions src/clusters/trackball_orbyl.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from clusters.default import DefaultCluster
import json
import os
import numpy as np
from dataclasses_json import dataclass_json
from dataclasses import dataclass
import clusters.trackball_cluster_abc as ca
from dactyl_manuform import rad2deg, pi
from typing import Any, Sequence

def debugprint(data):
Expand Down
2 changes: 0 additions & 2 deletions src/clusters/trackball_wilder.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import numpy as np
from dataclasses_json import dataclass_json
from dataclasses import dataclass
import clusters.trackball_orbyl as tbob
from dactyl_manuform import rad2deg, pi
from typing import Any, Sequence

def debugprint(data):
Expand Down
14 changes: 2 additions & 12 deletions src/dactyl_manuform.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
from numpy import pi
import os.path as path
import os
import copy
Expand Down Expand Up @@ -42,15 +41,6 @@ def debugprint(info):
print(info)



def deg2rad(degrees: float) -> float:
return degrees * pi / 180


def rad2deg(rad: float) -> float:
return rad * 180 / pi


def usize_dimension(Usize=1.5):
sa_length = 18.5
return Usize * sa_length
Expand Down Expand Up @@ -310,11 +300,11 @@ def valid_key(self, column, row):

def x_rot(self, shape, angle):
# debugprint('x_rot()')
return self.g.rotate(shape, [rad2deg(angle), 0, 0])
return self.g.rotate(shape, [np.rad2deg(angle), 0, 0])

def y_rot(self, shape, angle):
# debugprint('y_rot()')
return self.g.rotate(shape, [0, rad2deg(angle), 0])
return self.g.rotate(shape, [0, np.rad2deg(angle), 0])

def key_place(self, shape, column, row):
debugprint('key_place()')
Expand Down
15 changes: 6 additions & 9 deletions src/default_configuration.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import numpy as np
import sys
import getopt
import os
Expand All @@ -6,10 +7,6 @@
from dataclasses import dataclass
from typing import Any, Sequence

pi = 3.14159
d2r = pi / 180
r2d = 180 / pi

from oled.oled_clip import OLEDClipParameters as OLEDClip
from oled.oled_sliding import OLEDSlidingParameters as OLEDSliding
from oled.oled_undercut import OLEDUndercutParameters as OLEDUndercut
Expand Down Expand Up @@ -41,11 +38,11 @@ class ShapeConfiguration:
nrows = 5 # 5, # key rows
ncols = 6 # 6, # key columns

alpha: float = pi / 12.0 # curvature of the columns
beta: float = pi / 36.0 # curvature of the rows
alpha: float = np.pi / 12.0 # curvature of the columns
beta: float = np.pi / 36.0 # curvature of the rows
centercol: int = 3 # controls left_right tilt / tenting (higher number is more tenting)
centerrow_offset: int = 3 # rows from max, controls front_back tilt
tenting_angle: float = pi / 12.0 # or, change this for more precise tenting control
tenting_angle: float = np.pi / 12.0 # or, change this for more precise tenting control

# symmetry states if it is a symmetric or asymmetric bui. If asymmetric it doubles the generation time.
symmetric: bool = True # "asymmetric" or "symmetric"
Expand Down Expand Up @@ -136,10 +133,10 @@ class ShapeConfiguration:
## http://patentimages.storage.googleapis.com/EP0219944A2/imgf0002.png
## fixed_z overrides the z portion of the column ofsets above.
## NOTE: THIS DOESN'T WORK QUITE LIKE I'D HOPED.
fixed_angles: Sequence[float] = (d2r * 10, d2r * 10, 0, 0, 0, d2r * -15, d2r * -15)
fixed_angles: Sequence[float] = tuple(np.deg2rad((10, 10, 0, 0, 0, -15, -15)))
fixed_x: Sequence[float] = (-41.5, -22.5, 0, 20.3, 41.4, 65.5, 89.6) # relative to the middle finger
fixed_z: Sequence[float] = (12.1, 8.3, 0, 5, 10.7, 14.5, 17.5)
fixed_tenting: float = d2r * 0
fixed_tenting: float = np.deg2rad(0)

###################################
## SCREWS SETUP ##
Expand Down
15 changes: 6 additions & 9 deletions src/generate_configuration.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import numpy as np
import sys
import getopt
import os
import json


pi = 3.14159
d2r = pi / 180
r2d = 180 / pi

shape_config = {

# 'ENGINE': 'solid', # 'solid' = solid python / OpenSCAD, 'cadquery' = cadquery / OpenCascade
Expand All @@ -27,11 +24,11 @@
'nrows': 5, #5, # key rows
'ncols': 3, #6, # key columns

'alpha': pi / 12.0, # curvature of the columns
'beta': pi / 36.0, # curvature of the rows
'alpha': np.pi / 12.0, # curvature of the columns
'beta': np.pi / 36.0, # curvature of the rows
'centercol': 3, # controls left_right tilt / tenting (higher number is more tenting)
'centerrow_offset': 3, # rows from max, controls front_back tilt
'tenting_angle': pi / 12.0, # or, change this for more precise tenting control
'tenting_angle': np.pi / 12.0, # or, change this for more precise tenting control

# symmetry states if it is a symmetric or asymmetric bui. If asymmetric it doubles the generation time.
'symmetry': "symmetric", # "asymmetric" or "symmetric"
Expand Down Expand Up @@ -213,10 +210,10 @@
## http://patentimages.storage.googleapis.com/EP0219944A2/imgf0002.png
## fixed_z overrides the z portion of the column ofsets above.
## NOTE: THIS DOESN'T WORK QUITE LIKE I'D HOPED.
'fixed_angles': [d2r * 10, d2r * 10, 0, 0, 0, d2r * -15, d2r * -15],
'fixed_angles': list(np.deg2rad([10, 10, 0, 0, 0, -15, -15])),
'fixed_x': [-41.5, -22.5, 0, 20.3, 41.4, 65.5, 89.6], # relative to the middle finger
'fixed_z': [12.1, 8.3, 0, 5, 10.7, 14.5, 17.5],
'fixed_tenting': d2r * 0,
'fixed_tenting': np.deg2rad(0),

#################
## Switch Hole ##
Expand Down
9 changes: 2 additions & 7 deletions src/generate_configuration_orbyl_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
import os
import json


pi = 3.14159
d2r = pi / 180
r2d = 180 / pi

shape_config = {

'ENGINE': 'solid', # 'solid' = solid python / OpenSCAD, 'cadquery' = cadquery / OpenCascade
Expand Down Expand Up @@ -208,10 +203,10 @@
## http://patentimages.storage.googleapis.com/EP0219944A2/imgf0002.png
## fixed_z overrides the z portion of the column ofsets above.
## NOTE: THIS DOESN'T WORK QUITE LIKE I'D HOPED.
'fixed_angles': [d2r * 10, d2r * 10, 0, 0, 0, d2r * -15, d2r * -15],
'fixed_angles': list(np.deg2rad([10, 10, 0, 0, 0, -15, -15])),
'fixed_x': [-41.5, -22.5, 0, 20.3, 41.4, 65.5, 89.6], # relative to the middle finger
'fixed_z': [12.1, 8.3, 0, 5, 10.7, 14.5, 17.5],
'fixed_tenting': d2r * 0,
'fixed_tenting': np.deg2rad(0),

#################
## Switch Hole ##
Expand Down
15 changes: 6 additions & 9 deletions src/generate_configuration_test.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import numpy as np
import sys
import getopt
import os
import json


pi = 3.14159
d2r = pi / 180
r2d = 180 / pi

shape_config = {

'ENGINE': 'solid', # 'solid' = solid python / OpenSCAD, 'cadquery' = cadquery / OpenCascade
Expand All @@ -27,11 +24,11 @@
'nrows': 5, #5, # key rows
'ncols': 6, #6, # key columns

'alpha': pi / 12.0, # curvature of the columns
'beta': pi / 36.0, # curvature of the rows
'alpha': np.pi / 12.0, # curvature of the columns
'beta': np.pi / 36.0, # curvature of the rows
'centercol': 3, # controls left_right tilt / tenting (higher number is more tenting)
'centerrow_offset': 3, # rows from max, controls front_back tilt
'tenting_angle': pi / 12.0, # or, change this for more precise tenting control
'tenting_angle': np.pi / 12.0, # or, change this for more precise tenting control

# symmetry states if it is a symmetric or asymmetric bui. If asymmetric it doubles the generation time.
'symmetry': "symmetric", # "asymmetric" or "symmetric"
Expand Down Expand Up @@ -210,10 +207,10 @@
## http://patentimages.storage.googleapis.com/EP0219944A2/imgf0002.png
## fixed_z overrides the z portion of the column ofsets above.
## NOTE: THIS DOESN'T WORK QUITE LIKE I'D HOPED.
'fixed_angles': [d2r * 10, d2r * 10, 0, 0, 0, d2r * -15, d2r * -15],
'fixed_angles': list(np.deg2rad([10, 10, 0, 0, 0, -15, -15])),
'fixed_x': [-41.5, -22.5, 0, 20.3, 41.4, 65.5, 89.6], # relative to the middle finger
'fixed_z': [12.1, 8.3, 0, 5, 10.7, 14.5, 17.5],
'fixed_tenting': d2r * 0,
'fixed_tenting': np.deg2rad(0),

#################
## Switch Hole ##
Expand Down
1 change: 0 additions & 1 deletion src/helpers/helpers_abc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import cadquery as cq
from scipy.spatial import ConvexHull as sphull
import numpy as np


debug_trace = False
Expand Down
8 changes: 4 additions & 4 deletions src/helpers/helpers_blender.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import numpy as np
import bpy
import bmesh
import os
import sys
import time
import mathutils
from math import pi, radians, sin, cos
from contextlib import contextmanager


Expand Down Expand Up @@ -34,9 +34,9 @@ def cone(r1, r2, height):


def rotate(shape, angle):
bpy.ops.transform.rotate(value=-radians(angle[0]), orient_axis='X', center_override=(0.0, 0.0, 0.0))
bpy.ops.transform.rotate(value=-radians(angle[1]), orient_axis='Y', center_override=(0.0, 0.0, 0.0))
bpy.ops.transform.rotate(value=-radians(angle[2]), orient_axis='Z', center_override=(0.0, 0.0, 0.0))
bpy.ops.transform.rotate(value=-np.deg2rad(angle[0]), orient_axis='X', center_override=(0.0, 0.0, 0.0))
bpy.ops.transform.rotate(value=-np.deg2rad(angle[1]), orient_axis='Y', center_override=(0.0, 0.0, 0.0))
bpy.ops.transform.rotate(value=-np.deg2rad(angle[2]), orient_axis='Z', center_override=(0.0, 0.0, 0.0))
return

def translate(shape, vector):
Expand Down
8 changes: 3 additions & 5 deletions src/oled/oled_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ def debugprint(data):
pass
# print

def rad2deg(rad: float) -> float:
return rad * 180 / 3.14159

@dataclass_json
@dataclass
Expand Down Expand Up @@ -104,7 +102,7 @@ def process_parameters(self):
angle_x = np.arctan2(base_pt1[2] - base_pt2[2], base_pt1[1] - base_pt2[1])
angle_z = np.arctan2(base_pt1[0] - base_pt2[0], base_pt1[1] - base_pt2[1])

self.op.mount_rotation_xyz = (rad2deg(angle_x), 0, -rad2deg(angle_z)) + np.array(
self.op.mount_rotation_xyz = np.rad2deg((angle_x, 0, -angle_z)) + np.array(
self.op.rotation_offset)


Expand Down Expand Up @@ -133,9 +131,9 @@ def oled_position_rotation(self):
angle_z = np.arctan2(base_pt1[0] - base_pt2[0], base_pt1[1] - base_pt2[1])

if self.op.vertical:
oled_mount_rotation_xyz = (rad2deg(angle_x), 0, -rad2deg(angle_z)) + np.array(self.op.rotation_offset)
oled_mount_rotation_xyz = np.rad2deg((angle_x, 0, -angle_z)) + np.array(self.op.rotation_offset)
else:
oled_mount_rotation_xyz = (0, rad2deg(angle_x), -90) + np.array(self.op.rotation_offset)
oled_mount_rotation_xyz = (0, np.rad2deg(angle_x), -90) + np.array(self.op.rotation_offset)

return oled_mount_location_xyz, oled_mount_rotation_xyz

Expand Down
4 changes: 0 additions & 4 deletions src/oled/oled_clip.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
from os import path
import numpy as np
from dataclasses_json import dataclass_json
from dataclasses import dataclass
from typing import Any, Sequence, Tuple, Optional
Expand All @@ -10,9 +9,6 @@ def debugprint(data):
pass
# print

def rad2deg(rad: float) -> float:
return rad * 180 / pi

@dataclass_json
@dataclass
class OLEDClipParameters(oa.OLEDBaseParameters):
Expand Down
4 changes: 0 additions & 4 deletions src/oled/oled_sliding.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import json
import os
import numpy as np
from dataclasses_json import dataclass_json
from dataclasses import dataclass
from typing import Any, Sequence, Tuple, Optional
Expand All @@ -10,9 +9,6 @@ def debugprint(data):
pass
# print

def rad2deg(rad: float) -> float:
return rad * 180 / 3.14159


@dataclass_json
@dataclass
Expand Down
Loading