void generate_stellar_system() { planet_pointer planet; radians_per_rotation = 2.0 * PI; stellar_mass_ratio = random_number(0.6,1.3); stellar_luminosity_ratio = luminosity(stellar_mass_ratio); planet = distribute_planetary_masses(stellar_mass_ratio,stellar_luminosity_ratio,0.0,stellar_dust_limit(stellar_mass_ratio)); main_seq_life = 1.0E10 * (stellar_mass_ratio / stellar_luminosity_ratio); if ((main_seq_life >= 6.0E9)) age = random_number(1.0E9,6.0E9); else age = random_number(1.0E9,main_seq_life); r_ecosphere = sqrt(stellar_luminosity_ratio); r_greenhouse = r_ecosphere * GREENHOUSE_EFFECT_CONST; while (planet != NULL) { planet->orbit_zone = orbital_zone(planet->a); if (planet->gas_giant) { planet->density = empirical_density(planet->mass,planet->a,planet->gas_giant); planet->radius = volume_radius(planet->mass,planet->density); } else { planet->radius = kothari_radius(planet->mass,planet->a,planet->gas_giant,planet->orbit_zone); planet->density = volume_density(planet->mass,planet->radius); } planet->orbital_period = period(planet->a,planet->mass,stellar_mass_ratio); planet->day = day_length(planet->mass,planet->radius,planet->orbital_period,planet->e,planet->gas_giant); planet->resonant_period = spin_resonance; planet->axial_tilt = inclination(planet->a); planet->escape_velocity = escape_vel(planet->mass,planet->radius); planet->surface_accel = acceleration(planet->mass,planet->radius); planet->rms_velocity = rms_vel(MOLECULAR_NITROGEN,planet->a); planet->molecule_weight = molecule_limit(planet->a,planet->mass,planet->radius); if ((planet->gas_giant)) { planet->surface_grav = INCREDIBLY_LARGE_NUMBER; planet->greenhouse_effect = FALSE; planet->volatile_gas_inventory = INCREDIBLY_LARGE_NUMBER; planet->surface_pressure = INCREDIBLY_LARGE_NUMBER; planet->boil_point = INCREDIBLY_LARGE_NUMBER; planet->hydrosphere = INCREDIBLY_LARGE_NUMBER; planet->albedo = about(GAS_GIANT_ALBEDO,0.1); planet->surface_temp = INCREDIBLY_LARGE_NUMBER; } else { planet->surface_grav = gravity(planet->surface_accel); planet->greenhouse_effect = greenhouse(planet->orbit_zone,planet->a,r_greenhouse); planet->volatile_gas_inventory = vol_inventory(planet->mass,planet->escape_velocity,planet->rms_velocity,stellar_mass_ratio,planet->orbit_zone,planet->greenhouse_effect); planet->surface_pressure = pressure(planet->volatile_gas_inventory,planet->radius,planet->surface_grav); if ((planet->surface_pressure == 0.0)) planet->boil_point = 0.0; else planet->boil_point = boiling_point(planet->surface_pressure); iterate_surface_temp(&(planet)); } planet = planet->next_planet; } display_system( ); }
std::vector<std::vector<double> > calculate_luminosity(cimg_library::CImg<unsigned char> &image) { std::vector<std::vector<double> > luminosity_map(image.height(), std::vector<double>(image.width(), DBL_MAX)); for (int i = 0; i < image.height(); i++) { for (int j = 0; j < image.width(); j++) { luminosity_map[i][j] = luminosity(image.atXY(j, i, 0, 0), image.atXY(j, i, 0, 1), image.atXY(j, i, 0, 2)); } } return luminosity_map; }
void calc_color_pixel_from_spots(t_rt *rt, t_castray *cast, t_point *v_director) { t_obj *current_spot; get_point_hit(cast, v_director); get_normal_vector_sp(cast); rotate(&cast->v_normal, cast->obj_hit); normalize(&cast->v_normal); invers_normal(cast, v_director); current_spot = rt->spot; while (current_spot) { if (shadow(rt, cast, current_spot) == 0) luminosity(cast, current_spot, v_director); current_spot = current_spot->next; } }
void cornellBox(Scene *scene) { auto blue = std::shared_ptr<AbstractMaterial>( new LambertMaterial(Vector3D(0.1, 0.1, 1.0))); auto red = std::shared_ptr<AbstractMaterial>( new LambertMaterial(Vector3D(1.0, 0.1, 0.1))); auto white = std::shared_ptr<AbstractMaterial>( new LambertMaterial(Vector3D(1.0, 1.0, 1.0))); auto gray = std::shared_ptr<AbstractMaterial>( new LambertMaterial(Vector3D(0.2, 0.2, 0.2))); auto reflective = std::shared_ptr<AbstractMaterial>( new SpecularMaterial( Vector3D(0.8, 0.8, 0.8), Vector3D(INFINITY, INFINITY, INFINITY))); auto reflective_green = std::shared_ptr<AbstractMaterial>( new SpecularMaterial( Vector3D(0.1, 0.7, 0.05), Vector3D(INFINITY, INFINITY, INFINITY))); auto reflective_orange = std::shared_ptr<AbstractMaterial>( new SpecularMaterial( Vector3D(0.8, 0.4, 0.05), Vector3D(INFINITY, INFINITY, INFINITY))); auto refractive = std::shared_ptr<AbstractMaterial>( new SpecularMaterial( Vector3D(0.8, 0.8, 0.8), Vector3D(2.6, 2.6, 2.6))); auto refractive_yellow = std::shared_ptr<AbstractMaterial>( new SpecularMaterial( Vector3D(0.8, 0.8, 0.1), Vector3D(1.8, 1.8, 1.8))); auto refractive_magneta = std::shared_ptr<AbstractMaterial>( new SpecularMaterial( Vector3D(0.6, 0.1, 0.6), Vector3D(1.4, 1.4, 1.4))); auto ct1 = std::shared_ptr<AbstractMaterial>( new CookTorranceMaterial(reflective_orange, 0.1)); //auto ct2 = std::shared_ptr<AbstractMaterial>( //new CookTorranceMaterial(refractive_magneta, 0.25)); //auto ct3 = std::shared_ptr<AbstractMaterial>( //new CookTorranceMaterial(refractive_yellow, 0.01)); auto ward1 = std::shared_ptr<AbstractMaterial>( new WardAnisotropicMaterial(Vector3D(0.8, 0.4, 0.8), 0.001, 10.0)); auto ward2 = std::shared_ptr<AbstractMaterial>( new WardAnisotropicMaterial(Vector3D(0.1, 0.8, 0.4), 10.0, 0.001)); //auto refl_m = std::shared_ptr<AbstractMaterial>( //new CombinedMaterial({ //{0.2, gray}, //{0.8, reflective}})); //auto refr_m = std::shared_ptr<AbstractMaterial>( //new CombinedMaterial({ //{0.2, gray}, //{0.8, refractive}})); auto phong_m = std::shared_ptr<AbstractMaterial>( new PhongMaterial( Vector3D(0.8, 0.5, 0.6), 16.5)); auto sphere11 = std::shared_ptr<Object3D>(new HomogeneousObject( std::shared_ptr<Surface>(new Sphere( Vector3D(-2.5, -3.2, -2.5), 1.5)), phong_m)); scene->addObject(sphere11); auto sphere21 = std::shared_ptr<Object3D>(new HomogeneousObject( std::shared_ptr<Surface>(new Sphere( Vector3D(-2.5, 0.0, -2.5), 1.5)), reflective_green)); //refl_m)); scene->addObject(sphere21); auto sphere31 = std::shared_ptr<Object3D>(new HomogeneousObject( std::shared_ptr<Surface>(new Sphere( Vector3D(-2.5, 3.2, -2.5), 1.5)), gray)); scene->addObject(sphere31); auto sphere12 = std::shared_ptr<Object3D>(new HomogeneousObject( std::shared_ptr<Surface>(new Sphere( Vector3D(0.5, -3.2, -3.0), 1.0)), ct1)); scene->addObject(sphere12); auto sphere22 = std::shared_ptr<Object3D>(new HomogeneousObject( std::shared_ptr<Surface>(new Sphere( Vector3D(2.0, -1.1, -3.2), 0.8)), ward1)); scene->addObject(sphere22); auto sphere32 = std::shared_ptr<Object3D>(new HomogeneousObject( std::shared_ptr<Surface>(new Sphere( Vector3D(2.0, 1.1, -3.2), 0.8)), ward2)); scene->addObject(sphere32); auto sphere42 = std::shared_ptr<Object3D>(new HomogeneousObject( std::shared_ptr<Surface>(new Sphere( Vector3D(0.5, 3.2, -3.0), 1.0)), refractive_yellow)); scene->addObject(sphere42); auto red_tr_1 = std::shared_ptr<Object3D>(new HomogeneousObject( std::shared_ptr<Surface>(new Triangle( Vector3D(5.0, -5.0, -4.0), Vector3D(-5.0, -5.0, -4.0), Vector3D(-5.0, -5.0, 4.0))), red)); scene->addObject(red_tr_1); auto red_tr_2 = std::shared_ptr<Object3D>(new HomogeneousObject( std::shared_ptr<Surface>(new Triangle( Vector3D(-5.0, -5.0, 4.0), Vector3D(5.0, -5.0, 4.0), Vector3D(5.0, -5.0, -4.0))), red)); scene->addObject(red_tr_2); auto blue_tr_1 = std::shared_ptr<Object3D>(new HomogeneousObject( std::shared_ptr<Surface>(new Triangle( Vector3D(-5.0, 5.0, -4.0), Vector3D(5.0, 5.0, -4.0), Vector3D(-5.0, 5.0, 4.0))), blue)); scene->addObject(blue_tr_1); auto blue_tr_2 = std::shared_ptr<Object3D>(new HomogeneousObject( std::shared_ptr<Surface>(new Triangle( Vector3D(5.0, 5.0, 4.0), Vector3D(-5.0, 5.0, 4.0), Vector3D(5.0, 5.0, -4.0))), blue)); scene->addObject(blue_tr_2); auto ceiling_tr_1 = std::shared_ptr<Object3D>(new HomogeneousObject( std::shared_ptr<Surface>(new Triangle( Vector3D(5.0, -5.0, 4.0), Vector3D(-5.0, -5.0, 4.0), Vector3D(-5.0, 5.0, 4.0))), white)); scene->addObject(ceiling_tr_1); auto ceiling_tr_2 = std::shared_ptr<Object3D>(new HomogeneousObject( std::shared_ptr<Surface>(new Triangle( Vector3D(5.0, -5.0, 4.0), Vector3D(-5.0, 5.0, 4.0), Vector3D(5.0, 5.0, 4.0))), white)); scene->addObject(ceiling_tr_2); auto floor_tr_1 = std::shared_ptr<Object3D>(new HomogeneousObject( std::shared_ptr<Surface>(new Triangle( Vector3D(-5.0, -5.0, -4.0), Vector3D(5.0, -5.0, -4.0), Vector3D(-5.0, 5.0, -4.0))), white)); scene->addObject(floor_tr_1); auto floor_tr_2 = std::shared_ptr<Object3D>(new HomogeneousObject( std::shared_ptr<Surface>(new Triangle( Vector3D(-5.0, 5.0, -4.0), Vector3D(5.0, -5.0, -4.0), Vector3D(5.0, 5.0, -4.0))), white)); scene->addObject(floor_tr_2); auto back_wall_tr_1 = std::shared_ptr<Object3D>(new HomogeneousObject( std::shared_ptr<Surface>(new Triangle( Vector3D(-5.0, -5.0, -4.0), Vector3D(-5.0, 5.0, -4.0), Vector3D(-5.0, 5.0, 4.0))), white)); scene->addObject(back_wall_tr_1); auto back_wall_tr_2 = std::shared_ptr<Object3D>(new HomogeneousObject( std::shared_ptr<Surface>(new Triangle( Vector3D(-5.0, -5.0, -4.0), Vector3D(-5.0, 5.0, 4.0), Vector3D(-5.0, -5.0, 4.0))), white)); scene->addObject(back_wall_tr_2); Vector3D luminosity(2.0, 2.0, 2.0); //auto lamp_surface = std::shared_ptr<Surface>(new Sphere( //Vector3D(0.0, 0.0, 3.0), //0.4)); auto lamp_surface = std::shared_ptr<Surface>(new Triangle( Vector3D(0.0, 1.0, 3.99999), Vector3D(-3.0, 0.0, 3.99999), Vector3D(-1.0, 2.0, 3.99999))); auto lamp = std::shared_ptr<AbstractLightSource>(new LambertLightSource( lamp_surface, luminosity)); auto lamp_object = std::shared_ptr<Object3D>(new HomogeneousObject( lamp_surface, std::shared_ptr<AbstractMaterial>(new LightMaterial(luminosity)) )); scene->addLightSource(lamp, lamp_object); Vector3D luminosity2(1.5, 1.3, 0.6); auto lamp2_surface = std::shared_ptr<Surface>(new Triangle( Vector3D(0.0, -4.99999, 2.0), Vector3D(1.3, -4.99999, 0.0), Vector3D(1.7, -4.99999, 1.0))); auto lamp2 = std::shared_ptr<AbstractLightSource>(new LambertLightSource( lamp2_surface, luminosity2)); auto lamp2_object = std::shared_ptr<Object3D>(new HomogeneousObject( lamp2_surface, std::shared_ptr<AbstractMaterial>(new LightMaterial(luminosity2)) )); scene->addLightSource(lamp2, lamp2_object); }
stellar_system* generate_stellar_system(unsigned long random_seed) { planet* planet; double outer_dust_limit; stellar_system *system = malloc(sizeof(stellar_system)); system->first_planet = NULL; setup_seed(system, random_seed); system->star_mass_r = random_number(0.6, 1.3); /* was 0.6, 1.3 */ system->star_radius_r = about(pow(system->star_mass_r, 1.0 / 3.0), 0.05); /* for some unknown reason, only 3 digits wanted... */ system->star_radius_r = floor(system->star_radius_r * 1000.0) / 1000.0; system->star_lum_r = luminosity(system->star_mass_r); /* luminosity is proportional to T^4 and to area of star */ /* so temp is Tsol * 4th-root ( Lum / r^2 ) */ system->star_temp = 5650 * sqrt(sqrt(system->star_lum_r) / system->star_radius_r); /* ignore fractional degrees */ system->star_temp = floor(system->star_temp); sprintf(system->star_class, "%.16s", find_star_class(system->star_temp)); outer_dust_limit = stellar_dust_limit(system->star_mass_r); system->first_planet = distribute_planetary_masses(system, 0.0, outer_dust_limit); system->main_seq_life = 1.0E10 * (system->star_mass_r / system->star_lum_r); if (system->main_seq_life > 6.0E9) system->star_age = random_number(1.0E9, 6.0E9); else if (system->main_seq_life > 1.0E9) system->star_age = random_number(1.0E9, system->main_seq_life); else system->star_age = random_number(system->main_seq_life/10, system->main_seq_life); system->r_ecosphere = sqrt(system->star_lum_r); system->r_greenhouse = system->r_ecosphere * GREENHOUSE_EFFECT_CONST; for (planet = system->first_planet; planet != NULL; planet = planet->next_planet) { planet->orbit_zone = orbital_zone(system, planet->a); if (planet->gas_giant) { planet->density = empirical_density(system, planet->mass, planet->a, planet->gas_giant); planet->radius = volume_radius(planet->mass, planet->density); } else { planet->radius = kothari_radius(planet->mass, planet->gas_giant, planet->orbit_zone); planet->density = volume_density(planet->mass, planet->radius); } planet->orb_period = period(planet->a, planet->mass, system->star_mass_r); planet->day = day_length(system, planet->mass, planet->radius, planet->e, planet->density, planet->a, planet->orb_period, planet->gas_giant, system->star_mass_r); planet->resonant_period = system->resonance; planet->axial_tilt = inclination(planet->a); planet->esc_velocity = escape_velocity(planet->mass, planet->radius); planet->surf_accel = acceleration(planet->mass, planet->radius); planet->rms_velocity = rms_velocity(system, MOL_NITROGEN, planet->a); planet->molec_weight = molecule_limit(planet->mass, planet->radius); if ((planet->gas_giant)) { planet->surf_grav = INCREDIBLY_LARGE_NUMBER; planet->greenhouse_effect = false; planet->volatile_gas_inventory = INCREDIBLY_LARGE_NUMBER; planet->surf_pressure = INCREDIBLY_LARGE_NUMBER; planet->boil_point = INCREDIBLY_LARGE_NUMBER; planet->hydrosphere = INCREDIBLY_LARGE_NUMBER; planet->albedo = about(GAS_GIANT_ALBEDO, 0.1); planet->surf_temp = INCREDIBLY_LARGE_NUMBER; } else { planet->surf_grav = gravity(planet->surf_accel); planet->greenhouse_effect = greenhouse(planet->orbit_zone, planet->a, system->r_greenhouse); planet->volatile_gas_inventory = vol_inventory(planet->mass, planet->esc_velocity, planet->rms_velocity, system->star_mass_r, planet->orbit_zone, planet->greenhouse_effect); planet->surf_pressure = pressure(planet->volatile_gas_inventory, planet->radius, planet->surf_grav); if (planet->surf_pressure == 0.0) planet->boil_point = 0.0; else planet->boil_point = boiling_point(planet->surf_pressure); iterate_surface_temp(system, &(planet)); } #ifdef MOON if (args.make_moon) { #ifdef PROPER_MOON planet->first_moon = dist_moon_masses(planet->mass, star_lum_r, planet->e, 0.0, planet_dust_limit(planet->mass)); #else planet->first_moon = do_dist_moon_masses(planet->mass, planet->radius); { planet* moon = planet->first_moon; while (moon) { moon->radius = kothari_radius(moon->mass, 0, planet->orbit_zone); moon->density = volume_density(moon->mass, moon->radius); moon->density = random_number(1.5, moon->density * 1.1); if (moon->density < 1.5) moon->density = 1.5; moon->radius = volume_radius(moon->mass, moon->density); moon->orb_period = period(moon->a, moon->mass, planet->mass); moon->day = day_length(system, moon->mass, moon->radius, moon->e, moon->density, moon->a, moon->orb_period, moon->gas_giant, planet->mass); moon->resonant_period = system->resonance; moon->axial_tilt = inclination(moon->a); moon->esc_velocity = escape_vel(moon->mass, moon->radius); moon->surf_accel = acceleration(moon->mass, moon->radius); moon->rms_velocity = rms_vel(system, MOL_NITROGEN, planet->a); moon->molec_weight = molecule_limit(moon->mass, moon->radius); moon->surf_grav = gravity(moon->surf_accel); moon->greenhouse_effect = grnhouse(planet->orbit_zone, planet->a, system->r_greenhouse); moon->volatile_gas_inventory = vol_inventory(moon->mass, moon->esc_velocity, moon->rms_velocity, system->star_mass_r, planet->orbit_zone, moon->greenhouse_effect); moon->surf_pressure = pressure(moon->volatile_gas_inventory, moon->radius, moon->surf_grav); if ((moon->surf_pressure == 0.0)) moon->boil_point = 0.0; else moon->boil_point = boiling_point(moon->surf_pressure); iterate_surface_temp_moon(system, &planet, &moon); moon = moon->next_planet; } } #endif /* CC_MOON */ } #endif /* MOON */ } return system; }
void SmartMote::work(){ while(1){ /* se l'ora corrente è di scansione */ if(!(RTCC.hours() % 6) && (RTCC.minutes() >= 0x00 && RTCC.minutes() <= 0x05)){ AString data; AString message; AString answer; /* abilito il core timer (la prima volta è già abilitato) */ System::wakeCoreTimer(); /* accendo il led verde */ turnOnGreen(); /* accendo la seriale */ openUART(); /* accendo l'i2c */ openI2C(); /* prendo le misure */ data += mac(); data += luminosity(); data += ambientTempAndHum(); data += groundTemp(); data += groundHum(); data += battey(); /* compongo la stringa */ message += _PHP_CHUNK1; /* inserisco l'hostname */ message += getHost(); /* inserisco la seconda parte di richiesta http */ message += _PHP_CHUNK2; /* inserisco la lunghezza dei dati */ message += AString(static_cast<sint32>(data.size())); /* inserisco la terza parte di richiesta http */ message += _PHP_CHUNK3; /* inserisco i dati */ message += data; /* se fallisce l'inizializzazione dell'esp */ if(!m_net.initialize()){ /* notifico l'errore */ error(); } /* se fallisce l'avvio del dhcp */ if(!m_net.setDhcp(true)){ /* notifico l'errore */ error(); } /* se fallisce la connessione alla rete */ if(!m_net.joinAP(getSSID(), getKey())){ /* notifico l'errore */ error(); } /* se fallisce la connessione al server */ if(!m_net.connectToHost(getHost(), 80)){ /* notifico l'errore */ error(); } /* invio i dati */ m_net.send(message); /* aspetto l'ok */ m_net.waitForData(answer); /* notifico l'ok o lerrore dell'invio */ wasSuccess(answer); /* lascio l'ap */ m_net.leaveAP(); /* libero la memoria occupata dalle stringhe */ message.clear(); data.clear(); answer.clear(); } /* calcolo del tempo di sleep per il wifi */ m_net.sleep(getSleepTime()); /* punto la prossima sveglia */ setNextAlarm(); /* spengo il led verde */ turnOffGreen(); /* spengo l'uart */ closeUART(); /* chiudo l'i2c */ closeI2C(); /* spengo il core timer */ System::stopCoreTimer(); /* vado a dormire */ System::sleep(); } }
void star1d::dump_info() { DEBUG_FUNCNAME; printf("ESTER 1d model file"); printf(" (Version %s)\n", version.name.c_str()); // printf("\n1d ESTER model file (Version %d.%d rev %d",version.major,version.minor,version.rev); // if(version.svn) printf(".svn"); // printf(")\n\n"); printf("General parameters:\n\n"); printf("\tMass = %.5f Msun (%e g)\n",M/M_SUN,M); printf("\tRadius = %.5f Rsun (%e cm)\n",R/R_SUN,R); printf("\tLuminosity = %.4f Lsun (%e erg/s)\n",luminosity()/L_SUN,luminosity()); printf("\tTeff = %.2f\n",Teff()(0)); printf("\tlog(geff) = %.4f\n",log10(gsup())(0)); printf("\tX0=%.4f Y0=%.4f Z0=%.4f\n",X0,Y0,Z0); printf("\n"); if(conv==0) printf("No convective core\n\n"); else { printf("Convective core:\n\n"); double mcc=Mcore(); printf("\tMass_core = %.5f Msun (%e g)\n",mcc/M_SUN,mcc); double rcc=Rcore()(0); printf("\tRadius_core (p) = %.5f Rsun (%e cm)\n",rcc/R_SUN,rcc); printf("\tX_core/X_env = %.4f\n",Xc); printf("\n"); } printf("Central values:\n\n"); printf("\tTemperature = %e K\n",Tc); printf("\tDensity = %e g/cm3\n",rhoc); printf("\tPressure = %e dyn/cm2\n",pc); printf("\n"); printf("Grid parameters:\n\n"); printf("\t # of domains = %d\n",ndomains); printf("\t # of domains in convective core = %d\n",conv); printf("\t nr = %d (",nr); for(int n=0;n<ndomains;n++) { printf("%d",map.gl.npts[n]); if(n<ndomains-1) printf(","); } printf(")\n"); printf("\n"); printf("Additional parameters:\n\n"); printf("\tOpacity = %s\n",opa.name); printf("\tEquation of state = %s\n",eos.name); printf("\tNuclear reactions = %s\n",nuc.name); printf("\tAtmosphere = %s\n",atm.name); printf("\tsurff = %e\n",surff); printf("\tcore_convec = %d\n",core_convec); printf("\tenv_convec = %d\n",core_convec); printf("\tmin_core_size = %e\n",min_core_size); printf("\n"); printf("Tests:\n\n"); printf("\tVirial test = %e\n",virial()); printf("\tEnergy test = %e\n",energy_test()); printf("\n"); }