POV-Ray : Newsgroups : povray.windows : How to generate sphere and cylinder with csv file : Re: How to generate sphere and cylinder with csv file Server Time
8 Feb 2023 08:03:07 EST (-0500)
  Re: How to generate sphere and cylinder with csv file  
From: Jeff
Date: 8 Apr 2017 09:55:00
Message: <web.58e8eb3bae95604b4de507a60@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "Jeff" <jef### [at] gmailcom> wrote:

here is my code now:

global_settings {
 assumed_gamma 1.0
 #default {texture {pigment {rgb <1, 1, 1>} finish {ambient 1}}}
 ambient_light rgb <1, 1, 1> // <======== flat, even illumination
}

#include "colors.inc"

camera {
 location <55,25,80>
 right    x*image_width/image_height
 look_at <55,0,126>
}

light_source{ <10,10,-10>  color rgb <1, 1, 1>}

#declare Feet = 12;
//  Sized image Map - 1 unit thick box
#declare XSize = 4*Feet;
#declare ImageMap = pigment {image_map {png "beijing.png" once} };
#declare Resolution = max_extent (ImageMap);
#declare Resolution = Resolution + <0, 0, 1>;

#declare ImageMappedBox =
 box {0, 1
  texture {
   pigment {ImageMap}
  }
  translate <0, 0, 0>
  scale Resolution*(1/Resolution.x)*XSize
  rotate <90,0,0>
  //translate y*(Resolution.y / Resolution.x)*XSize/2
 }
object {ImageMappedBox translate <31,0,115>}
object {ImageMappedBox translate <31,5,115>}
object {ImageMappedBox translate <31,10,115>}
object {ImageMappedBox translate <31,15,115>}

----------------what does the code blocks below
do?---------------------------#declare EarthRadius = 6367; //radius in km
#declare EarthRadius = 6367*0.621371; //radius in mi

#macro S2C (Spherical)
 // input - 2d vector: <Latitude, Longitude>
 #local Lat = radians (Spherical.x);
 #local Lon = radians (Spherical.y);
 #local X = EarthRadius * cos(Lat) * cos(Lon);
 #local Y = EarthRadius * cos(Lat) * sin(Lon);
 #local Z = EarthRadius * sin(Lat);
 #local Cartesian = <X, Y, Z>;
 Cartesian;
#end // end macro S2C

#macro C2S (Cartesian)

 #local R = sqrt(pow(Cartesian.x, 2) * pow(Cartesian.y, 2) * pow(Cartesian.z,
2));
 #local Lat = degrees (asin (Cartesian.z / R));
 #local Lon = degrees (atan2 (Cartesian.y, Cartesian.x));
 #local LatLon = <Lat, Lon>;
 LatLon;
#end // end macro C2S
------------------------------------------------------------------
//  data format: "bus", "CN/Beijing", "bus2382659521", 39.9067192, 116.4093833,
//    etc.
#declare Mode = "bus";
#declare City = "CN/Beijing";
#declare ID = "bus23822659521";
#declare Latitude = 39.9067192;
#declare Longitude = 116.4093833;

--------------------------------------------------------------
#declare modez = 'bus' = 0; 'subway' = 5; 'rail' = 10; 'tram = 15
here i try to declare different z position for different mode, so they are not
in the same height(layer of picture)
---------------------------------------------------------------
// count locations for sizing array
#declare Locations = 0;
#fopen nodes "nodes.csv" read
#while (defined (nodes))
 #read (nodes, mode, city, ID, Latitude, Longitude)
 #declare Locations = Locations + 1;
#end
#fclose nodes

#declare _mode = bus[Locations];
#declare _city = CN/Beijing[Locations];
#declare _ID = bus2382659521[Locations];
#declare _Latitude = 39.9067192[Locations];
#declare _Longitude = 116.4093833[Locations];
#declare _XYZ = Longitude[Locations];Latitude[Locations];modesz[Locations]

// input data into array
#declare Datapoint = 0;
#fopen links "links.csv" read
#while (defined (links))
 #read (links, Mode, Source, Target, Length)

 #declare _Mode [Datapoint] = Mode;
 #declare _Source [Datapoint] = Source;
 #declare _Target [Datapoint] = Target;
 #declare _Length [Datapoint] = Length;
 #declare _XYZ [Datapoint] = S2C (<_Longitude[Datapoint],
_Latitude[Datapoint,_XYZ[Datapoint]>);
 #declare Datapoint = Datapoint + 1;
#end
#fclose links

#declare Marker = 0.25;
#declare Line = 0.05;
#declare Linecolor = pigment {Magenta};

#for (Point, 0, Locations-1)

 #if (Mode = "bus")
  #declare Color = pigment {Red};
 #elseif (Mode = "subway")
  #declare Color = pigment {Green};
 #elseif (Mode = "rail")
  #declare Color = pigment {Blue};
 #elseif (Mode = "tram")
  #declare Color = pigment {Yellow};
 #else
  #debug "Unidentified Location Type.  \n"
  #declare Color = pigment {White};
 #end

 #declare S = 1; //<0.1, 0.1, 1/4000>;
 #declare T = <1350, 1130, -3500>;

 sphere {0.3, Marker pigment {Color} translate _XYZ[Point]*S translate T}

 #if (Point > 0)
  cylinder {LastPoint*S, _XYZ[Point]*S, Line pigment {Linecolor} translate T}
 #end // end if

 #debug concat( "Vector = ", vstr(3, _XYZ[Point]*S, ", ", 3, 0), " \n")

 #declare LastPoint = _XYZ[Point];

#end // end for Point


Post a reply to this message

Copyright 2003-2021 Persistence of Vision Raytracer Pty. Ltd.