diff --git a/Zome.rb b/Zome.rb index 9eca3da..0f5d277 100644 --- a/Zome.rb +++ b/Zome.rb @@ -1,9 +1,13 @@ require 'sketchup.rb' require 'extensions.rb' -zome_extension = SketchupExtension.new('Zome', 'Zome/core.rb') -zome_extension.version = '1.2.4' -zome_extension.copyright = '2018' -zome_extension.description = 'Zome Creator - PolarZonahedron' -zome_extension.creator = 'Jo Takion ' -Sketchup.register_extension(zome_extension, true) +module Takion + module Zome + zome_extension = SketchupExtension.new('Zome', 'Zome/core.rb') + zome_extension.version = '1.2.4' + zome_extension.copyright = '2018' + zome_extension.description = 'Zome Creator - PolarZonahedron' + zome_extension.creator = 'Jo Takion ' + Sketchup.register_extension(zome_extension, true) + end +end diff --git a/Zome.rbz b/Zome.rbz index 0caa717..c00f8a0 100644 Binary files a/Zome.rbz and b/Zome.rbz differ diff --git a/Zome/core.rb b/Zome/core.rb index 6c22fc1..1df32e0 100644 --- a/Zome/core.rb +++ b/Zome/core.rb @@ -3,604 +3,463 @@ require 'sketchup.rb' include Math module Takion -class RhombiZonaedrePolaire - def self.generation func - self.new func - end - def initialize func - eval("#{func}") - end - def start - $mo = Sketchup.active_model - Sketchup::set_status_text("Zome modelisation in progress...") - $mo.start_operation "PolarZonahedron - Structure Processing" - @t1 = Time.now - $entities = $mo.active_entities.add_group.entities - end - def ending - $mo.commit_operation - if not $takion_z_l - UI.messagebox("\nZome Creator" << - "\OpenSource software developed by Jo - jo@redcat.ninja" << - "\nhttps://github.com/takion/zome-polar-rhombizonahedron/", "Zome Creator - Open software") - $takion_z_l = true - end - end - def add_note(msg) - $mo.add_note msg, 0, 0.03 - end - def rayon_polygone_regulier n_cotes,segment_length - return (segment_length/2.0)/(Math.sin((360.0/n_cotes)/(2.0*(180.0/Math::PI)))) - end - def aire_polygone_regulier n_cotes,segment_length,radius - if not radius - radius = rayon_polygone_regulier n_cotes,segment_length - end - area = n_cotes*(0.5*(segment_length*Math.sqrt((radius*radius)-((segment_length*segment_length)/4.0))))*$u_inch*1000.0 - return area.inch - end - def draw_face(pts) - if($takion_zome['T_Modelisation']=='Faces') - face = $entities.add_face(pts) - face.back_material = $takion_zome['RVB_BACK_FACES'] - face.material = $takion_zome['RVB_FACES'] - end - if($takion_zome['T_Modelisation']=='Squelette') - line = $entities.add_line( pts ) - end - if($takion_zome['T_Modelisation']=='Tubes') - line = $entities.add_line(pts) - create_tubes(line,$takion_zome['L_TubesDiametre']) - end - end - def create_tubes(line,radius) - edges = [line] - verts=[] - newVerts=[] - startEdge=startVert=nil - edges.each {|edge|verts.push(edge.vertices)} - verts.flatten! - vertsShort=[] - vertsLong=[] - verts.each do |v| - if vertsLong.include?(v) - vertsShort.push(v) - else - vertsLong.push(v) + module Zome + class Zome + def self.gen_dh + obj = self.new + obj.zome_dh() end - end - if (startVert=(vertsLong-vertsShort).first)==nil - startVert=vertsLong.first - closed=true - startEdge = startVert.edges.first - else - closed=false - startEdge = (edges & startVert.edges).first - end - #SORT VERTICES, LIMITING TO THOSE IN THE SELECTION SET - if startVert==startEdge.start - newVerts=[startVert] - counter=0 - while newVerts.length < verts.length - edges.each do |edge| - if edge.end==newVerts.last - newVerts.push(edge.start) - elsif edge.start==newVerts.last - newVerts.push(edge.end) - end - end - counter+=1 - if counter > verts.length - return nil if UI.messagebox("There seems to be a problem. Try again?", MB_YESNO)!=6 - newVerts.reverse! - reversed=true + def self.gen_al + obj = self.new + obj.zome_al() + end + def self.gen_ah + obj = self.new + obj.zome_ah() + end + def self.gen_ad + obj = self.new + obj.zome_ad() + end + + def initialize + + end + def start + @mo = Sketchup.active_model + Sketchup::set_status_text("Zome modelisation in progress...") + @mo.start_operation "PolarZonahedron - Structure Processing" + @t1 = Time.now + @entities = @mo.active_entities.add_group.entities + end + def ending + @mo.commit_operation + end + def add_note(msg) + @mo.add_note msg, 0, 0.03 + end + def rayon_polygone_regulier n_cotes,segment_length + return (segment_length/2.0)/(Math.sin((360.0/n_cotes)/(2.0*(180.0/Math::PI)))) + end + def aire_polygone_regulier n_cotes,segment_length,radius + if not radius + radius = rayon_polygone_regulier n_cotes,segment_length end + area = n_cotes*(0.5*(segment_length*Math.sqrt((radius*radius)-((segment_length*segment_length)/4.0))))*@u_inch*1000.0 + return area.inch end - else - newVerts=[startVert] - counter=0 - while newVerts.length < verts.length - edges.each do |edge| - if edge.end==newVerts.last - newVerts.push(edge.start) - elsif edge.start==newVerts.last - newVerts.push(edge.end) - end + def draw_face(pts) + if(@gen_zome['T_Modelisation']=='Faces') + face = @entities.add_face(pts) + face.back_material = @gen_zome['RVB_BACK_FACES'] + face.material = @gen_zome['RVB_FACES'] end - counter+=1 - if counter > verts.length - return nil if UI.messagebox("There seems to be a problem. Try again?", MB_YESNO)!=6 - newVerts.reverse! - reversed=true + if(@gen_zome['T_Modelisation']=='Squelette') + line = @entities.add_line( pts ) end end - end - ###newVerts.uniq! ### allow IF closed - newVerts.reverse! if reversed - #CONVERT VERTICES TO POINT3Ds - newVerts.collect!{|x| x.position} - ###newVerts.push(newVerts[0]) - ### now have an array of vertices in order with NO forced closed loop ... - ### - do stuff - ### - pt1 = newVerts[0] - pt2 = newVerts[1] - vec = pt1.vector_to pt2 - theCircle = $entities.add_circle pt1, vec, radius - # theCircle = $entities.add_ngon pt1, vec, radius, 4 - theFace = $entities.add_face theCircle - i = 0 - @@theEdges= [] - 0.upto(newVerts.length - 2) do |something| - @@theEdges[i] = $entities.add_line(newVerts[i],newVerts[i+1]) ### make vertices into edges - i = i + 1 - end - ### follow me along selected edges - theFace.reverse!.followme @@theEdges ### - $mo.commit_operation - ### restore selection set of edges and display them - i = 0 - theEdgeX = [] - 0.upto(newVerts.length - 2) do |something| - theEdgeX[i] = $entities.add_line(newVerts[i],newVerts[i+1]) ### make vertices into edges - i = i + 1 - end - $mo.selection.clear - $mo.selection.add theEdgeX - end - def create_polarzonaedre(draw, bases, niveaux, sinus, cosinus, hypotenus) - @arretes_nb = (bases*2*niveaux)-bases - @tirants_nb = (bases*2*niveaux)/2 - @segments_nb = @arretes_nb+@tirants_nb - @connecteurs_nb = (bases*niveaux)+1 - - msg = "" - vector = Geom::Vector3d.new(sinus,0,cosinus) - vector.length = hypotenus - pts=[] - points=[] - pts[0] = Geom::Point3d.new(0,0,0) - - 1.upto(niveaux){ |i| - p_rotate = Geom::Transformation.rotation( pts[0] , Geom::Vector3d.new(0,0,1), i*2*PI/bases ) + def create_polarzonaedre(draw, bases, niveaux, sinus, cosinus, hypotenus) + @arretes_nb = (bases*2*niveaux)-bases + @tirants_nb = (bases*2*niveaux)/2 + @segments_nb = @arretes_nb+@tirants_nb + @connecteurs_nb = (bases*niveaux)+1 + + msg = "" + vector = Geom::Vector3d.new(sinus,0,cosinus) + vector.length = hypotenus + pts=[] + points=[] + pts[0] = Geom::Point3d.new(0,0,0) + + 1.upto(niveaux){ |i| + p_rotate = Geom::Transformation.rotation( pts[0] , Geom::Vector3d.new(0,0,1), i*2*PI/bases ) - pts[1] = pts[0].transform( vector ) - pts[3] = pts[1].transform( p_rotate ) - pts[2] = pts[3].transform( vector ) - # mb = i*2*PI/bases - # UI.messagebox "#{mb.radians}" - points[i] = [] - 0.upto(bases-1){ |j| - f_rotate = Geom::Transformation.rotation( Geom::Point3d.new(0,0,0) , Geom::Vector3d.new(0,0,1), j*2*PI/bases) - points[i][j] = pts.collect{|p| p.transform(f_rotate)} - - } - pts[0] = pts[3] - } - rot = Geom::Transformation.rotation [0,0,0], X_AXIS, 180.degrees - hauteur_r = points[niveaux-1][0][2][2] + pts[1] = pts[0].transform( vector ) + pts[3] = pts[1].transform( p_rotate ) + pts[2] = pts[3].transform( vector ) + # mb = i*2*PI/bases + # UI.messagebox "#{mb.radians}" + points[i] = [] + 0.upto(bases-1){ |j| + f_rotate = Geom::Transformation.rotation( Geom::Point3d.new(0,0,0) , Geom::Vector3d.new(0,0,1), j*2*PI/bases) + points[i][j] = pts.collect{|p| p.transform(f_rotate)} + + } + pts[0] = pts[3] + } + rot = Geom::Transformation.rotation [0,0,0], X_AXIS, 180.degrees + hauteur_r = points[niveaux-1][0][2][2] - faces = [] - 1.upto(niveaux){ |i| - 0.upto(bases-1){ |j| - points[i][j].collect{|p| - p.transform!(rot) - p[2]+=hauteur_r + faces = [] + 1.upto(niveaux){ |i| + 0.upto(bases-1){ |j| + points[i][j].collect{|p| + p.transform!(rot) + p[2]+=hauteur_r + } + if(draw==true) + pt1 = points[i][j][1] + pt3 = points[i][j][3] + pt4 = points[i][j][0] + if(@gen_zome['T_Ties']=='Horizontal') + if(i - raise "Number of layers different from the number of needed sides" if ( $takion_zome['N_Niveaux'] == $takion_zome['N_Cotes'] ) - raise "Required a number of layers not equal to null" if ( $takion_zome['N_Niveaux'] <= 0 ) - raise "Minimum 2 layers required for coherent Zome" if ( $takion_zome['N_Niveaux'] < 2 ) - raise "Required a number of sides not equal to null" if( $takion_zome['N_Cotes'] <= 0 ) - raise "Minimum 3 sides required for coherent Zome" if ( $takion_zome['N_Cotes'] < 3 ) - raise "Required height not equal to null" if ( $takion_zome['L_Hauteur'] <= 0 ) - raise "Angle can't be equal to 90" if ( $takion_zome['L_AngleDeForme'] == 90 ) - # - rescue - UI.messagebox $!.message - retry - end - if($takion_zome['T_Modelisation']=="Tubes") - begin - results_tubes = UI.inputbox ['Diamètre des Tubes'],[28.mm],[],'Modelisation Tubes' - return unless results_tubes - $takion_zome['L_TubesDiametre'] = results_tubes[0] - raise "Required a value not equal to none" if ( $takion_zome['L_TubesDiametre'] <= 0 ) - rescue - UI.messagebox $!.message - retry - end - end - - start - - angle_forme = $takion_zome['L_AngleDeForme'].degrees - hypotenus = $takion_zome['L_Arrete'] - msg = "" - - sinus = cos(angle_forme) - cosinus = sin(angle_forme) - retour = create_polarzonaedre(true,$takion_zome['N_Cotes'],$takion_zome['N_Niveaux'],sinus,cosinus,hypotenus) - - msg += "Sides: #{$takion_zome['N_Cotes']} \n" - msg += "Layers: #{$takion_zome['N_Niveaux']} \n" - msg += "Diameter: #{retour[0].inch} \n" - msg += "Height: #{retour[1].inch} \n" - msg += "Shape angle: #{angle_forme.radians} \n" - msg += "Edges: #{hypotenus.inch} \n" - - msg += retour[2] - - add_note msg - ending - end - - def zome_ah - config = [ - ['N_Cotes',10,'Sides of rotation around the axis'], - ['N_Niveaux',5,'Vertical Layer'], - ['L_AngleDeForme',35.2643896827547,'Shape angle'], - ['L_Hauteur',3000.mm,'Height at the top'], - ['T_Ties','Horizontal','Ties',"Horizontal|None"], - ['L_RayonConnecteurs',150.mm,'Radius of the connectors'], - ['T_Ground','No','Ground',"Yes|No"], - ['T_Modelisation','Faces','Modelisation',"Squelette|Faces|Tubes"] - ] - $takion_zome = {} if not $takion_zome - 0.upto(config.length-1){ |i| - $takion_zome[config[i][0]] = config[i][1] if not $takion_zome[config[i][0]] - } - - results = nil - prompts = [] - defaults = [] - drops = [] - 0.upto(config.length-1){ |i| - defaults.push config[i][1] - prompts.push config[i][2] - if(config[i][3]) - drops.push config[i][3] - else - drops.push '' + def create_tiles params + + end + def rapport_complet params + sixbranch_connection = (@connecteurs_nb-(params['N_Cotes']*2))-1 + msg = "" + msg += " Sides: #{params["N_Cotes"]} \n" + msg += " Layers: #{params["N_Niveaux"]} \n" + msg += " Height: #{params["L_Hauteur"]} \n" + msg += " Ground diameter: #{params["L_Diametre"]} \n" + # msg += " Aire au sol: #{@ground_area}² \n" + msg += "\n Number of connectors: #{@connecteurs_nb} \n" + msg += " #{params['N_Cotes']} x Connector 4 branches \n" + msg += " #{sixbranch_connection} x Connector 6 branches \n" + msg += " #{params['N_Cotes']} x Connector 5 branches \n" + msg += " 1 x Connector #{params['N_Cotes']} branches \n" + msg += "\n Segments total number: #{@segments_nb} \n" + # msg += " Longeur totale des segments: #{segments_lenth} \n" + msg += " Number of Ties: #{@tirants_nb} \n" + + msg += "\n© Zome Creator \OpenSource software developed by Jo - jo@redcat.ninja \nhttps://github.com/takion/zome-polar-rhombizonahedron/" + + return msg + end + def zome_al + config = [ + ['N_Cotes',10,'Sides of rotation around the axis'], + ['N_Niveaux',5,'Vertical Layer'], + ['L_AngleDeForme',35.2643896827547,'Shape angle'], + ['L_Arrete',1.m,'Edges'], + ['T_Ties','Horizontal','Ties',"Horizontal|None"], + ['T_Ground','No','Ground',"Yes|No"], + ['T_Modelisation','Faces','Modelisation',"Squelette|Faces"] + ] + @gen_zome = {} if not @gen_zome + 0.upto(config.length-1){ |i| + @gen_zome[config[i][0]] = config[i][1] if not @gen_zome[config[i][0]] + } + + results = nil + prompts = [] + defaults = [] + drops = [] + 0.upto(config.length-1){ |i| + defaults.push config[i][1] + prompts.push config[i][2] + if(config[i][3]) + drops.push config[i][3] + else + drops.push '' + end + } + begin + results = UI.inputbox prompts,defaults,drops,'Polar Zonohedron based on shape angle and edges' + return unless results + 0.upto(config.length-1){ |i| + @gen_zome[config[i][0]] = results[i] + } + # + raise "Number of layers different from the number of needed sides" if ( @gen_zome['N_Niveaux'] == @gen_zome['N_Cotes'] ) + raise "Required a number of layers not equal to null" if ( @gen_zome['N_Niveaux'] <= 0 ) + raise "Minimum 2 layers required for coherent Zome" if ( @gen_zome['N_Niveaux'] < 2 ) + raise "Required a number of sides not equal to null" if( @gen_zome['N_Cotes'] <= 0 ) + raise "Minimum 3 sides required for coherent Zome" if ( @gen_zome['N_Cotes'] < 3 ) + raise "Angle can't be equal to 90" if ( @gen_zome['L_AngleDeForme'] == 90 ) + # + rescue + #UI.messagebox $!.message + #retry + end + + start + + angle_forme = @gen_zome['L_AngleDeForme'].degrees + hypotenus = @gen_zome['L_Arrete'] + msg = "" + + sinus = cos(angle_forme) + cosinus = sin(angle_forme) + retour = create_polarzonaedre(true,@gen_zome['N_Cotes'],@gen_zome['N_Niveaux'],sinus,cosinus,hypotenus) + + msg += "Sides: #{@gen_zome['N_Cotes']} \n" + msg += "Layers: #{@gen_zome['N_Niveaux']} \n" + msg += "Diameter: #{retour[0].inch} \n" + msg += "Height: #{retour[1].inch} \n" + msg += "Shape angle: #{angle_forme.radians} \n" + msg += "Edges: #{hypotenus.inch} \n" + + msg += retour[2] + + add_note msg + ending end - } - begin - results = UI.inputbox prompts,defaults,drops,'RhombiZonaèdre Polar by shapes angle and height' - return unless results - 0.upto(config.length-1){ |i| - $takion_zome[config[i][0]] = results[i] - } - # - raise "Required a number of layers not equal to null" if ( $takion_zome['N_Niveaux'] <= 0 ) - raise "Minimum 2 layers required for coherent Zome" if ( $takion_zome['N_Niveaux'] < 2 ) - raise "Required a number of sides not equal to null" if( $takion_zome['N_Cotes'] <= 0 ) - raise "Minimum 3 sides required for coherent Zome" if ( $takion_zome['N_Cotes'] < 3 ) - raise "Required height not equal to null" if ( $takion_zome['L_Hauteur'] <= 0 ) - raise "Angle can't be 90" if ( $takion_zome['L_AngleDeForme'] == 90 ) - # - rescue - UI.messagebox $!.message - retry - end - if($takion_zome['T_Modelisation']=="Tubes") - begin - results_tubes = UI.inputbox ['Diamètre des Tubes'],[28.mm],[],'Modelisation Tubes' - return unless results_tubes - $takion_zome['L_TubesDiametre'] = results_tubes[0] - raise "Valeur non nulle requise" if ( $takion_zome['L_TubesDiametre'] <= 0 ) - rescue - UI.messagebox $!.message - retry - end - end - - start - - msg = "" - - angle_forme = $takion_zome['L_AngleDeForme'].degrees - adjacent = $takion_zome['L_Hauteur']/$takion_zome['N_Niveaux'] - hypotenus = adjacent/angle_forme - oppose = sqrt(hypotenus*hypotenus - adjacent*adjacent) - - sinus = cos(angle_forme) - cosinus = sin(angle_forme) - - retour1 = create_polarzonaedre(false,$takion_zome['N_Cotes'],$takion_zome['N_Niveaux'],sinus,cosinus,hypotenus) - hypotenus *= $takion_zome['L_Hauteur']/retour1[1] - retour2 = create_polarzonaedre(true,$takion_zome['N_Cotes'],$takion_zome['N_Niveaux'],sinus,cosinus,hypotenus) - - msg += "Bases: #{$takion_zome['N_Cotes']} \n" - msg += "Layers: #{$takion_zome['N_Niveaux']} \n" - msg += "Diameter: #{retour2[0].inch} \n" - msg += "Height: #{retour2[1].inch} \n" - msg += "Shape angle: #{angle_forme.radians} \n" - msg += "Edges: #{hypotenus.inch} \n" - msg += retour2[2] - add_note msg - ending - end + def zome_ah + config = [ + ['N_Cotes',10,'Sides of rotation around the axis'], + ['N_Niveaux',5,'Vertical Layer'], + ['L_AngleDeForme',35.2643896827547,'Shape angle'], + ['L_Hauteur',3000.mm,'Height at the top'], + ['T_Ties','Horizontal','Ties',"Horizontal|None"], + ['T_Ground','No','Ground',"Yes|No"], + ['T_Modelisation','Faces','Modelisation',"Squelette|Faces"] + ] + @gen_zome = {} if not @gen_zome + 0.upto(config.length-1){ |i| + @gen_zome[config[i][0]] = config[i][1] if not @gen_zome[config[i][0]] + } + + results = nil + prompts = [] + defaults = [] + drops = [] + 0.upto(config.length-1){ |i| + defaults.push config[i][1] + prompts.push config[i][2] + if(config[i][3]) + drops.push config[i][3] + else + drops.push '' + end + } + begin + results = UI.inputbox prompts,defaults,drops,'RhombiZonaèdre Polar by shapes angle and height' + return unless results + 0.upto(config.length-1){ |i| + @gen_zome[config[i][0]] = results[i] + } + # + raise "Required a number of layers not equal to null" if ( @gen_zome['N_Niveaux'] <= 0 ) + raise "Minimum 2 layers required for coherent Zome" if ( @gen_zome['N_Niveaux'] < 2 ) + raise "Required a number of sides not equal to null" if( @gen_zome['N_Cotes'] <= 0 ) + raise "Minimum 3 sides required for coherent Zome" if ( @gen_zome['N_Cotes'] < 3 ) + raise "Required height not equal to null" if ( @gen_zome['L_Hauteur'] <= 0 ) + raise "Angle can't be 90" if ( @gen_zome['L_AngleDeForme'] == 90 ) + # + rescue + UI.messagebox $!.message + retry + end + + start + + msg = "" + + angle_forme = @gen_zome['L_AngleDeForme'].degrees - def zomes_ad - config = [ - ['N_Cotes',10,'Sides of rotation around the axis'], - ['N_Niveaux',5,'Vertical Layer'], - ['L_AngleDeForme',35.2643896827547,'Shape angle'], - ['L_Diametre',6000.mm,'Ground diameter'], - ['L_RayonConnecteurs',150.mm,'Radius of the connectors'], - ['T_Ground','No','Ground',"Yes|No"], - ['T_Modelisation','Faces','Modelisation',"Squelette|Faces|Tubes"] - ] - $takion_zome = {} if not $takion_zome - 0.upto(config.length-1){ |i| - $takion_zome[config[i][0]] = config[i][1] if not $takion_zome[config[i][0]] - } - - results = nil - prompts = [] - defaults = [] - drops = [] - 0.upto(config.length-1){ |i| - defaults.push config[i][1] - prompts.push config[i][2] - if(config[i][3]) - drops.push config[i][3] - else - drops.push '' + adjacent = @gen_zome['L_Hauteur']/@gen_zome['N_Niveaux'] + hypotenus = adjacent/angle_forme + oppose = sqrt(hypotenus*hypotenus - adjacent*adjacent) + + sinus = cos(angle_forme) + cosinus = sin(angle_forme) + + retour1 = create_polarzonaedre(false,@gen_zome['N_Cotes'],@gen_zome['N_Niveaux'],sinus,cosinus,hypotenus) + hypotenus *= @gen_zome['L_Hauteur']/retour1[1] + retour2 = create_polarzonaedre(true,@gen_zome['N_Cotes'],@gen_zome['N_Niveaux'],sinus,cosinus,hypotenus) + + msg += "Bases: #{@gen_zome['N_Cotes']} \n" + msg += "Layers: #{@gen_zome['N_Niveaux']} \n" + msg += "Diameter: #{retour2[0].inch} \n" + msg += "Height: #{retour2[1].inch} \n" + msg += "Shape angle: #{angle_forme.radians} \n" + msg += "Edges: #{hypotenus.inch} \n" + msg += retour2[2] + add_note msg + ending end - } - begin - results = UI.inputbox prompts,defaults,drops,'Polar Zonohedron based on shape angle and diameter' - return unless results - 0.upto(config.length-1){ |i| - $takion_zome[config[i][0]] = results[i] - } - # - raise "Required a number of layers not equal to null" if ( $takion_zome['N_Niveaux'] <= 0 ) - raise "Minimum 2 layers required for a coherent Zome" if ( $takion_zome['N_Niveaux'] < 2 ) - raise "Required a number of sides not equal to null" if( $takion_zome['N_Cotes'] <= 0 ) - raise "Minimum 3 sides required for a coherent Zome" if ( $takion_zome['N_Cotes'] < 3 ) - raise "Required a diameter not equal to null" if ( $takion_zome['L_Diametre'] <= 0 ) - raise "The angle can't be at 90" if ( $takion_zome['L_AngleDeForme'] == 90 ) - # - rescue - UI.messagebox $!.message - retry - end - if($takion_zome['T_Modelisation']=="Tubes") - begin - results_tubes = UI.inputbox ['Diamètre des Tubes'],[28.mm],[],'Modelisation Tubes' - return unless results_tubes - $takion_zome['L_TubesDiametre'] = results_tubes[0] - raise "Valeur non nulle requise" if ( $takion_zome['L_TubesDiametre'] <= 0 ) - rescue - UI.messagebox $!.message - retry - end - end - - start - - msg = "" - - angle_forme = $takion_zome['L_AngleDeForme'].degrees - hypotenus = $takion_zome['L_Diametre']/2/PI - - sinus = cos(angle_forme) - cosinus = sin(angle_forme) - - retour1 = create_polarzonaedre(false,$takion_zome['N_Cotes'],$takion_zome['N_Niveaux'],sinus,cosinus,hypotenus) - - hypotenus *= $takion_zome['L_Diametre']/retour1[0] - retour2 = create_polarzonaedre(true,$takion_zome['N_Cotes'],$takion_zome['N_Niveaux'],sinus,cosinus,hypotenus) - - msg += "Bases: #{$takion_zome['N_Cotes']} \n" - msg += "Layers: #{$takion_zome['N_Niveaux']} \n" - msg += "Diameter: #{$takion_zome['L_Diametre'].inch} \n" - msg += "Height: #{retour2[1].inch} \n" - msg += "Shape angle: #{angle_forme.radians} \n" - msg += "Edges: #{hypotenus.inch} \n" - msg += retour2[2] - add_note msg - ending - end + + def zome_ad + config = [ + ['N_Cotes',10,'Sides of rotation around the axis'], + ['N_Niveaux',5,'Vertical Layer'], + ['L_AngleDeForme',35.2643896827547,'Shape angle'], + ['L_Diametre',6000.mm,'Ground diameter'], + ['T_Ties','Horizontal','Ties',"Horizontal|None"], + ['T_Ground','No','Ground',"Yes|No"], + ['T_Modelisation','Faces','Modelisation',"Squelette|Faces"] + ] + @gen_zome = {} if not @gen_zome + 0.upto(config.length-1){ |i| + @gen_zome[config[i][0]] = config[i][1] if not @gen_zome[config[i][0]] + } + + results = nil + prompts = [] + defaults = [] + drops = [] + 0.upto(config.length-1){ |i| + defaults.push config[i][1] + prompts.push config[i][2] + if(config[i][3]) + drops.push config[i][3] + else + drops.push '' + end + } + begin + results = UI.inputbox prompts,defaults,drops,'RhombiZonaèdre Polar by shapes angle and height' + return unless results + 0.upto(config.length-1){ |i| + @gen_zome[config[i][0]] = results[i] + } + # + raise "Required a number of layers not equal to null" if ( @gen_zome['N_Niveaux'] <= 0 ) + raise "Minimum 2 layers required for coherent Zome" if ( @gen_zome['N_Niveaux'] < 2 ) + raise "Required a number of sides not equal to null" if( @gen_zome['N_Cotes'] <= 0 ) + raise "Minimum 3 sides required for coherent Zome" if ( @gen_zome['N_Cotes'] < 3 ) + raise "Required diameter not equal to null" if ( @gen_zome['L_Diametre'] <= 0 ) + raise "Angle can't be 90" if ( @gen_zome['L_AngleDeForme'] == 90 ) + # + rescue + UI.messagebox $!.message + retry + end + + start + + msg = "" + + angle_forme = @gen_zome['L_AngleDeForme'].degrees + + hypotenus = @gen_zome['L_Diametre']/2/PI + sinus = cos(angle_forme) + cosinus = sin(angle_forme) + + retour1 = create_polarzonaedre(false,@gen_zome['N_Cotes'],@gen_zome['N_Niveaux'],sinus,cosinus,hypotenus) + hypotenus *= @gen_zome['L_Diametre']/retour1[0] + retour2 = create_polarzonaedre(true,@gen_zome['N_Cotes'],@gen_zome['N_Niveaux'],sinus,cosinus,hypotenus) + + msg += "Bases: #{@gen_zome['N_Cotes']} \n" + msg += "Layers: #{@gen_zome['N_Niveaux']} \n" + msg += "Diameter: #{retour2[0].inch} \n" + msg += "Height: #{retour2[1].inch} \n" + msg += "Shape angle: #{angle_forme.radians} \n" + msg += "Edges: #{hypotenus.inch} \n" + msg += retour2[2] + add_note msg + ending + end - def zome_dh - config = [ - ['N_Cotes',10,'Sides of rotation around the axis'], - ['N_Niveaux',5,'Vertical Layer'], - ['L_Diametre',6000.mm,'Ground diameter'], - ['L_Hauteur',3000.mm,'Height at the top'], - ['T_Ties','None','Ties',"Horizontal|None"], - ['L_RayonConnecteurs',150.mm,'Radius of the connectors'], - ['T_Ground','No','Ground',"Yes|No"], - ['T_Modelisation','Squelette','Modelisation',"Squelette|Faces|Tubes"] - ] - $takion_zome = {} if not $takion_zome - 0.upto(config.length-1){ |i| - $takion_zome[config[i][0]] = config[i][1] if not $takion_zome[config[i][0]] - } - - results = nil - prompts = [] - defaults = [] - drops = [] - 0.upto(config.length-1){ |i| - defaults.push config[i][1] - prompts.push config[i][2] - if(config[i][3]) - drops.push config[i][3] - else - drops.push '' + def zome_dh + config = [ + ['N_Cotes',10,'Sides of rotation around the axis'], + ['N_Niveaux',5,'Vertical Layer'], + ['L_Diametre',6000.mm,'Ground diameter'], + ['L_Hauteur',3000.mm,'Height at the top'], + ['T_Ties','None','Ties',"Horizontal|None"], + ['T_Ground','No','Ground',"Yes|No"], + ['T_Modelisation','Faces','Modelisation',"Squelette|Faces"] + ] + @gen_zome = {} if not @gen_zome + 0.upto(config.length-1){ |i| + @gen_zome[config[i][0]] = config[i][1] if not @gen_zome[config[i][0]] + } + + results = nil + prompts = [] + defaults = [] + drops = [] + 0.upto(config.length-1){ |i| + defaults.push config[i][1] + prompts.push config[i][2] + if(config[i][3]) + drops.push config[i][3] + else + drops.push '' + end + } + begin + results = UI.inputbox prompts,defaults,drops,'Polar Zonohedron based on diameter and height' + return unless results + 0.upto(config.length-1){ |i| + @gen_zome[config[i][0]] = results[i] + } + # + raise "Required a number of layers not equal to null" if ( @gen_zome['N_Niveaux'] <= 0 ) + raise "Minimum 2 layers required for a coherent Zome" if ( @gen_zome['N_Niveaux'] < 2 ) + raise "Required a number of sides not equal to null" if( @gen_zome['N_Cotes'] <= 0 ) + raise "Minimum 3 sides required for a coherent Zome" if ( @gen_zome['N_Cotes'] < 3 ) + raise "Diameter can't be equal to null" if ( @gen_zome['L_Diametre'] <= 0 ) + raise "Required height not equal to null" if ( @gen_zome['L_Hauteur'] <= 0 ) + # + rescue + UI.messagebox $!.message + retry + end + + start + + + msg = "" + + adjacent = @gen_zome['L_Hauteur']/@gen_zome['N_Niveaux'] + + oppose = @gen_zome['L_Diametre']/@gen_zome['N_Niveaux']/2 + hypotenus = sqrt(adjacent*adjacent + oppose*oppose) + sinus = oppose/hypotenus + cosinus = adjacent/hypotenus + retour1 = create_polarzonaedre(false,@gen_zome['N_Cotes'],@gen_zome['N_Niveaux'],sinus,cosinus,hypotenus) + ndiametre = @gen_zome['L_Diametre']*(@gen_zome['L_Diametre']/retour1[0]) + + oppose = ndiametre/@gen_zome['N_Niveaux']/2 + hypotenus = sqrt(adjacent*adjacent + oppose*oppose) + sinus = oppose/hypotenus + cosinus = adjacent/hypotenus + retour2 = create_polarzonaedre(true,@gen_zome['N_Cotes'],@gen_zome['N_Niveaux'],sinus,cosinus,hypotenus) + + msg += "Bases: #{@gen_zome['N_Cotes']} \n" + msg += "Layers: #{@gen_zome['N_Niveaux']} \n" + msg += "Diameter: #{@gen_zome['L_Diametre'].inch} \n" + msg += "Height: #{@gen_zome['L_Hauteur'].inch} \n" + msg += "Edges: #{hypotenus.inch} \n" + # msg += "Shape angle: #{asin(cosinus).radians} \n" + msg += "Shape angle: #{acos(sinus).radians} \n" + msg += "Angle between the axes and the edge of the top layer: #{asin(sinus).radians} \n" + + msg += retour2[2] + + add_note msg + ending end - } - begin - results = UI.inputbox prompts,defaults,drops,'Polar Zonohedron based on diameter and height' - return unless results - 0.upto(config.length-1){ |i| - $takion_zome[config[i][0]] = results[i] - } - # - raise "Required a number of layers not equal to null" if ( $takion_zome['N_Niveaux'] <= 0 ) - raise "Minimum 2 layers required for a coherent Zome" if ( $takion_zome['N_Niveaux'] < 2 ) - raise "Required a number of sides not equal to null" if( $takion_zome['N_Cotes'] <= 0 ) - raise "Minimum 3 sides required for a coherent Zome" if ( $takion_zome['N_Cotes'] < 3 ) - raise "Diameter can't be equal to null" if ( $takion_zome['L_Diametre'] <= 0 ) - raise "Required height not equal to null" if ( $takion_zome['L_Hauteur'] <= 0 ) - # - rescue - UI.messagebox $!.message - retry - end - if($takion_zome['T_Modelisation']=="Tubes") - begin - results_tubes = UI.inputbox ['Diamètre des Tubes'],[28.mm],[],'Modelisation Tubes' - return unless results_tubes - $takion_zome['L_TubesDiametre'] = results_tubes[0] - raise "Valeur non nulle requise" if ( $takion_zome['L_TubesDiametre'] <= 0 ) - rescue - UI.messagebox $!.message - retry - end end - - start - - - msg = "" - - adjacent = $takion_zome['L_Hauteur']/$takion_zome['N_Niveaux'] - - oppose = $takion_zome['L_Diametre']/$takion_zome['N_Niveaux']/2 - hypotenus = sqrt(adjacent*adjacent + oppose*oppose) - sinus = oppose/hypotenus - cosinus = adjacent/hypotenus - retour1 = create_polarzonaedre(false,$takion_zome['N_Cotes'],$takion_zome['N_Niveaux'],sinus,cosinus,hypotenus) - ndiametre = $takion_zome['L_Diametre']*($takion_zome['L_Diametre']/retour1[0]) - - oppose = ndiametre/$takion_zome['N_Niveaux']/2 - hypotenus = sqrt(adjacent*adjacent + oppose*oppose) - sinus = oppose/hypotenus - cosinus = adjacent/hypotenus - retour2 = create_polarzonaedre(true,$takion_zome['N_Cotes'],$takion_zome['N_Niveaux'],sinus,cosinus,hypotenus) - - msg += "Bases: #{$takion_zome['N_Cotes']} \n" - msg += "Layers: #{$takion_zome['N_Niveaux']} \n" - msg += "Diameter: #{$takion_zome['L_Diametre'].inch} \n" - msg += "Height: #{$takion_zome['L_Hauteur'].inch} \n" - msg += "Edges: #{hypotenus.inch} \n" - # msg += "Shape angle: #{asin(cosinus).radians} \n" - msg += "Shape angle: #{acos(sinus).radians} \n" - msg += "Angle between the axes and the edge of the top layer: #{asin(sinus).radians} \n" - - msg += retour2[2] - - add_note msg - ending + zomes_menu = UI.menu("Plugins").add_submenu("Zome") + zomes_menu.add_item("By diameter and height") { Zome.gen_dh() } + zomes_menu.add_item("By angle and edges") { Zome.gen_al() } + zomes_menu.add_item("By angle and height") { Zome.gen_ah() } + zomes_menu.add_item("By angle and diameter") { Zome.gen_ad() } + file_loaded(File.basename(__FILE__)) end end -end - -zomes_menu = UI.menu("Plugins").add_submenu("Zome") -zomes_menu.add_item("By diameter and height") { Takion::RhombiZonaedrePolaire.generation('zome_dh') } -zomes_menu.add_item("By angle and edges") { Takion::RhombiZonaedrePolaire.generation('zome_al') } -zomes_menu.add_item("By angle and height") { Takion::RhombiZonaedrePolaire.generation('zome_ah') } -zomes_menu.add_item("By angle and diameter") { Takion::RhombiZonaedrePolaire.generation('zomes_ad') } -file_loaded(File.basename(__FILE__))