// Cup Holder for Stroller
// Dimensions are in millimeters
// Constants
// Increase smoothness of curved surfaces
$fn = 100; 

/* [Cup holder dimensions] */
 
// Lower section inner diameter
lower_diameter = 58; 
// Upper section inner diameter
upper_diameter = 67; 
// Slightly larger than the widest part of the interior
outer_diameter = upper_diameter+5;
// Total height of the cup holder
height = 110; 
// Thickness of the base
base_thickness = 3; 
// Height of the lower section
step_height = 50; 

/* [Snap clamp dimensions] */
// 125 mm circumference as requested
handlebar_circumference = 125; 
handlebar_diameter = handlebar_circumference / PI;
// Reduced thickness for more flexibility
clamp_thickness = 5; 
// Slightly reduced height
clamp_height = 40; 
// Increased gap angle for easier attachment
gap_angle = 70; 
gap_width = 30; // Adjusted to 30 mm as requested
// Increased flexibility factor
flexibility = 2.5; 

module cup_holder() {
  difference() {
    union(){
      cylinder(d = outer_diameter, h = height);
      
      //Tapering
      translate([-20, -upper_diameter-3 ,height*.5])
      cube([clamp_height,60,clamp_height-25]);
    }
    // Upper section
    translate([0, 0, base_thickness + step_height])
    cylinder(d = upper_diameter, h = height);

    // Lower section
    translate([0, 0, base_thickness])
    cylinder(d = lower_diameter, h = height);
    
    // Subtracting clamp hole for bolt and nut
    translate([0, -upper_diameter+16, 0])
    cylinder(height,6,6); 
  }
}




// Main body of the clamp
module clamp_body() {
    translate([-3,-12,0])
  difference() {
    {
      cylinder(h=clamp_height, d=handlebar_diameter + clamp_thickness * 3, center=true);
    }
    cylinder(h=clamp_height + 1, d=handlebar_diameter, center=true);
    translate([-20, -(handlebar_diameter/4 + clamp_thickness), 0])
      cube([gap_width+8, (handlebar_diameter*2 + clamp_thickness * 2), clamp_height + 10], center=true);
  }
}

// Snap feature
module snap_feature() {
  rotate([0, 0, gap_angle/2 - 5])
  translate([handlebar_diameter/2 + clamp_thickness/2, 0, 0])
  rotate([90, 0, 0])
  linear_extrude(height = clamp_thickness, center = true)
  polygon([
    [0, -clamp_height/2],
    [clamp_thickness/2, -clamp_height/2],
    [clamp_thickness/2, clamp_height/2],
    [0, clamp_height/2],
    [-clamp_thickness/4, clamp_height/4],
    [-clamp_thickness/4, -clamp_height/4]
  ]);
}

module rib_shape(){
translate([-25,-45,70])
rotate([-30, 0, 0])
  rotate([0, 90, 0])
linear_extrude(clamp_height*1.2)
hull(){
  translate([1,-5,0])
  circle(1);
  
  translate([0,5,0])
  circle(1);
  
  translate([8,9.5,0])
  circle(1);
}}

//Clamp taper
module Clamp_taper(){
 translate([0,0,10])
translate([-20,-45,70])
rotate([-30, 0, 0])
  rotate([0, 90, 0])
linear_extrude(clamp_height)
hull(){
  translate([3.5,-17.2,0])
  circle(1);
   
  translate([-5.5,15,0])
  circle(1);
   
  translate([5,10,0])
  circle(1);
}}

// Final clamp assembly
module snap_clamp() {
  difference() {
    clamp_body();
  }
}
// Main Assembly


{

translate([0, -upper_diameter-11,height*0.6])
rotate([0, 90, 0])
snap_clamp();



//Text inscription
difference(){
cup_holder();
 
    
translate([0, 0 ,height*0.6])
rotate([0,90,0])
rotate([0,0,90])
linear_extrude(height = 50)
                    text("Ellie og Vilde", size = 6, font = "Helvetica:style=Bold", halign = "center", valign = "center");
}

}






//Bottom clamp
translate([-90,40,height*.5+clamp_height-25])
mirror([0,0,1])
{


translate([0, -upper_diameter-11,height*0.6])
rotate([0, 90, 0])
snap_clamp();



//Text inscription
difference(){
cup_holder();
    
    translate([0,0,-1.5])
 cylinder(d = outer_diameter+.05, h = height+2);
    
translate([0, 0 ,height*0.6])
rotate([0,90,0])
rotate([0,0,90])
linear_extrude(height = 50)
                    text("Ellie og Vilde", size = 6, font = "Helvetica:style=Bold", halign = "center", valign = "center");
}

}

