From 4138ed438e1111bafbe3bee17021a922966c334b Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Mon, 9 Aug 2021 15:10:59 +0100 Subject: [PATCH 1/2] Added ability to display camera field of view. --- vitamins/camera.scad | 17 ++++++++++++++++- vitamins/cameras.scad | 9 ++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/vitamins/camera.scad b/vitamins/camera.scad index b4c1717..8ad06d2 100644 --- a/vitamins/camera.scad +++ b/vitamins/camera.scad @@ -28,6 +28,7 @@ function camera_lens_offset(type) = type[3]; //! Offset of the lens center fro function camera_lens(type) = type[4]; //! Stack of lens parts, can be round, rectangular or rounded rectangular, with optional tapered aperture function camera_connector_pos(type) = type[5]; //! The flex connector block for the camera itself's position function camera_connector_size(type)= type[6]; //! The flex connector block for the camera itself's size +function camera_fov(type) = type[7]; //! The field of view of the camera lens module camera_lens(type, offset = 0, show_lens = true) //! Draw the lens stack, with optional offset for making a clearance hole color(grey(20)) @@ -57,7 +58,7 @@ module camera_lens(type, offset = 0, show_lens = true) //! Draw the lens stack, } } -module camera(type, show_lens = true) { //! Draw specified PCB camera +module camera(type, show_lens = true, fov = undef, fov_distance = 0) { //! Draw specified PCB camera vitamin(str("camera(", type[0], "): ", type[1])); pcb = camera_pcb(type); @@ -66,6 +67,20 @@ module camera(type, show_lens = true) { //! Draw specified PCB camera translate_z(pcb_thickness(pcb)) { camera_lens(type, show_lens = show_lens); + if (show_lens && fov_distance > 0) { + lens = camera_lens(type); + fov = is_undef(fov) ? camera_fov(type) : fov; + #translate_z(lens[2][0].z) // note: use of # is deliberate, to show highlighted field of view + translate(camera_lens_offset(type)) + if (is_list(fov)) + hull() { + cube([lens[1][1]/2, lens[1][1]/2, eps], center=true); + translate_z(fov_distance) + cube([2 * fov_distance * (sin(fov.x) + (fov.x > 90 ? 1 : 0)), 2 * fov_distance * (sin(fov.y) + (fov.y > 90 ? 1 : 0)), eps], center=true); + } + else + cylinder(r1 = lens[0][1] / 2, r2 = fov_distance * (sin(fov) + (fov > 90 ? 1 : 0)), h = fov_distance); + } conn = camera_connector_size(type); if(conn) { diff --git a/vitamins/cameras.scad b/vitamins/cameras.scad index cab5d46..b4cccc3 100644 --- a/vitamins/cameras.scad +++ b/vitamins/cameras.scad @@ -32,7 +32,8 @@ rpi_camera_v1 = ["rpi_camera_v1", "Raspberry Pi camera V1", rpi_camera_v1_pcb, [ [[0, 0, 4], 7.5 / 2], [[0, 0, 5], 5.5 / 2, [1.5/2, 2/2, 0.5]], ], - [0, 12 - 1.5 - 2.5], [8, 5, 1] + [0, 12 - 1.5 - 2.5], [8, 5, 1], + [54, 41] // FOV ]; rpi_camera_v2_pcb = ["", "", 25, 23.862, 1, 2, 2.2, 0, "green", false, [[2, -2], [-2, -2], [2, -14.5], [-2, -14.5]], @@ -47,7 +48,8 @@ rpi_camera_v2 = ["rpi_camera_v2", "Raspberry Pi camera V2", rpi_camera_v2_pcb, [ [[0, 0, 4], 7.5 / 2], [[0, 0, 5], 5.5 / 2, [1.5/2, 2/2, 0.5]], ], - [-13.8 + 12.5, 23.862 / 2 - 4.7], [8.5, 4, 1] + [-13.8 + 12.5, 23.862 / 2 - 4.7], [8.5, 4, 1], + [62.2, 48.8] // FOV ]; rpi_camera_pcb = ["", "", 36, 36, 1.6, 0, 3.2, 0, "green", false, [[3.5, -3.5], [-3.5, -3.5], [3.5, 3.5], [-3.5, 3.5]], @@ -65,7 +67,8 @@ rpi_camera = ["rpi_camera", "Raspberry Pi focusable camera", rpi_camera_pcb, [0, [[0, 0, 12], 6], [[0, 11, 4.3], 14 / 2, [8/2, 11/2, 1]], ], - [0, 18 - 1.5 - 2.5], [8, 5, 1.6] + [0, 18 - 1.5 - 2.5], [8, 5, 1.6], + 63 // FOV ]; cameras = [rpi_camera_v1, rpi_camera_v2, rpi_camera]; From 71f935de8e24673a10707cfe434a2faaf3de1c28 Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Tue, 14 Dec 2021 12:11:03 +0000 Subject: [PATCH 2/2] Corrected FOV handling. --- vitamins/camera.scad | 14 ++++++-------- vitamins/cameras.scad | 3 +-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/vitamins/camera.scad b/vitamins/camera.scad index 8ad06d2..b676038 100644 --- a/vitamins/camera.scad +++ b/vitamins/camera.scad @@ -58,7 +58,7 @@ module camera_lens(type, offset = 0, show_lens = true) //! Draw the lens stack, } } -module camera(type, show_lens = true, fov = undef, fov_distance = 0) { //! Draw specified PCB camera +module camera(type, show_lens = true, fov_distance = 0, fov = undef) { //! Draw specified PCB camera vitamin(str("camera(", type[0], "): ", type[1])); pcb = camera_pcb(type); @@ -67,19 +67,17 @@ module camera(type, show_lens = true, fov = undef, fov_distance = 0) { translate_z(pcb_thickness(pcb)) { camera_lens(type, show_lens = show_lens); - if (show_lens && fov_distance > 0) { + if (show_lens&& fov_distance > 0) { lens = camera_lens(type); fov = is_undef(fov) ? camera_fov(type) : fov; - #translate_z(lens[2][0].z) // note: use of # is deliberate, to show highlighted field of view - translate(camera_lens_offset(type)) - if (is_list(fov)) + if (is_list(fov)) + #translate_z(lens[2][0].z) // note: use of # is deliberate, to show highlighted field of view + translate(camera_lens_offset(type)) hull() { cube([lens[1][1]/2, lens[1][1]/2, eps], center=true); translate_z(fov_distance) - cube([2 * fov_distance * (sin(fov.x) + (fov.x > 90 ? 1 : 0)), 2 * fov_distance * (sin(fov.y) + (fov.y > 90 ? 1 : 0)), eps], center=true); + cube([2 * fov_distance * tan(fov.x / 2), 2 * fov_distance * tan(fov.y / 2), eps], center=true); } - else - cylinder(r1 = lens[0][1] / 2, r2 = fov_distance * (sin(fov) + (fov > 90 ? 1 : 0)), h = fov_distance); } conn = camera_connector_size(type); diff --git a/vitamins/cameras.scad b/vitamins/cameras.scad index b4cccc3..8232b99 100644 --- a/vitamins/cameras.scad +++ b/vitamins/cameras.scad @@ -67,8 +67,7 @@ rpi_camera = ["rpi_camera", "Raspberry Pi focusable camera", rpi_camera_pcb, [0, [[0, 0, 12], 6], [[0, 11, 4.3], 14 / 2, [8/2, 11/2, 1]], ], - [0, 18 - 1.5 - 2.5], [8, 5, 1.6], - 63 // FOV + [0, 18 - 1.5 - 2.5], [8, 5, 1.6] ]; cameras = [rpi_camera_v1, rpi_camera_v2, rpi_camera];