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:12:19 EST (-0500)
  Re: How to generate sphere and cylinder with csv file  
From: Jeff
Date: 7 Apr 2017 13:00:01
Message: <web.58e7c48bae95604bb8de811f0@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> clipka <ano### [at] anonymousorg> wrote:
>
> > My guess would be that you have arbitrary text in the CSV file; in that
> > case, you'll need to make sure it is enclosed in double quotes, e.g.
> >
> >     "Foo"
> >
> > instead of
> >
> >     Foo
>
> Correct.
> Jeff, look at the comment in the code:
> //  data format: "bus", "CN/Beijing", "bus2382659521", 116.4093833, 39.9067192,
> //    etc.
>
> That's exactly how it all will need to be formatted.
> I'd probably use a spreadsheet, "copy" the data into an adjacent set of cells,
> by using a formula that surrounds the relevant data with double quotes (the
> String Literal POV-Ray is wanting for the #read directive) and commas and then
> copying and pasting that into a text document, or displaying the data on a
> separate spreadsheet and saving it to CSV format that way.
>
> ="\""&A1&"\", "&"\""&A2&"\", "&A3&"\", "&A4&"\", "&A5&"\","
> or something like that
>
> POV-Ray is a raytracer that generates 2D static images.  It can't render a 3D
> model that you can then move around and inspect on-the-fly.
> You can make an animation from a large series of static images sequentially
> arranged, but it's as interactive as a VHS movie.
>
> It seems like you have a fair amount of stuff you want to do - so for now, I'd
> step back for a sec, write up some simple scenes from scratch, "wrap your head
> around" POV-Ray's syntax, error messages, definitions, and other things peculiar
> to it, and just get your 4 image layers working all by themselves.
> You will have to use "transmit all 0.9" (or some other value) for the top 3
> layers, so that you can see through them.
>
>
> My standard bit of saved code for Image Mapping a box is:
>
> #declare Feet = 12;
> //  Sized image Map - 1 unit thick box
> #declare XSize = 4*Feet;
> #declare ImageMap = pigment {image_map {png "MyImage.png" once} };
> #declare Resolution = max_extent (ImageMap);
> #declare Resolution = Resolution + <0, 0, 1>;
>
>
> #declare ImageMappedBox =
>  box {0, 1
>   texture {
>    pigment {ImageMap}
>   }
>   translate <-0.5, -0.5, -0.5>
>   scale Resolution*(1/Resolution.x)*XSize
>   //translate y*(Resolution.y / Resolution.x)*XSize/2
>  }
>
> object {ImageMappedBox translate <0, 0, 0>}
>
> Set yourself up some visible axes, and maybe a grid to give yourself some
> orientation in the scene and maybe a sphere at the origin for a reference
> marker.  (AT the beginning, it's easy to forget to include a camera, a light
> source, get you axes mixed up, use right-hand rule instead of left hand rule,
> etc)
>
> You're going to need all these skills once you start creating a scene that's set
> up for rendering frames for an animation - because you're going to need to
> understand how the guts of the code works when you write the formulas with the
> clock variable to control how everything is rendered in each successive frame.
>
> Do everything stepwise, and save a working result with a different filename, so
> that as you progressive, you don't overwrite your Last-Known-Good scene.
>
> 1. make a basic scene with axes
> 2. add a grid to give a sense of scale
> 3. add 4 layered boxes
> 4. move you camera around by editing the code and rerendering
> 4a. save as a different filename
> 5. add image_map textures
> 6. adjust transmit and scaling
> ..
> ..
> ..
> N. add point and lines from the first scene code
> ..
> ..
> ..
> N++. define the formulas to create a series of renders for animating
> N++1.  Run you .ini animation file and let it churn them all out
> N++2. Use a 3rd party software (VideoMach, etc) to make the static images into a
> video file
>
> and then tweak, tweak, tweak, rewrite and debug   ;)
>
> There are plenty of example scenes, Lohmueller's site, the standard include
> drop-down menu, and the POV-Ray scene files sections of the forum.
>
> Only you will know exactly what you want, and we can't write it all for you -
> you're best served by spending a few hours ( ;) ) grappling with what we all
> struggled with when we first started doing this.
>
> But we are here to help  :)


hi, thank you so much. here is my code now. so, i have for layers , and a red
sphere.

#include "colors.inc"

camera {
       location <55,30,90>
       look_at <55,0,126>
       rotate <0,clock*360,0>
       }

light_source  {
              <55,30,75>
              color White
              }

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

#declare EarthRadius = 6367*0.621371; //radius in m

#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>;
---------------------------------------------------------------------------
>>#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

"" is there anything that i have to change in this part(above and below)? bcos i
just realized i gave the wrong questions, i said "use the
"lon" column as the Y position of the sphere, and "lat" column as the Z
position?" , but its actually use the "lon" column as the X position of the
sphere and "lat" as the Y positions of the sphere""

#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

"" HERE TOO ? ""
------------------------------------------------------------------------
#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 <30,0,110>}
object {ImageMappedBox translate <30,5,110>}
object {ImageMappedBox translate <30,10,110>}
object {ImageMappedBox translate <30,15,110>}

sphere {
        <55,15,110>, 2
        pigment {Red}
}
--------------------------------------------------------
>>//  data format: "bus", "CN/Beijing", "bus2382659521", 116.4093833, 39.9067192,
//    etc.
#declare Type = "";
#declare Location = "";
#declare ID = "";
#declare Latitude = 0;
#declare Longitude = 0;

""and this part, do i have to do it just one of 'em? or what? , i would like to
change it like this (below) ""

#declare Mode = "";
#declare City = "";
#declare ID = "";
#declare Latitude = 0;
#declare Longitude = 0;
------------------------------------------------
>>// count locations for sizing array
#declare Locations = 0;------> " what does this line do ? "
#fopen DataFile "LatLongData.txt" read
#while (defined (DataFile))
 #read (DataFile, Type, Location, ID, Latitude, Longitude)
 #declare Locations = Locations + 1;
#end
#fclose DataFile

"" this part, i would like to change it to like this (below)""

// count locations for sizing array
#declare Locations = 0; # i dont understand what is the "Locations" for????
#fopen Nodes "nodes.csv" read
#while (defined (Nodes))
 #read (Nodes, Mode, City, ID, Longitude, Latitude)
 #declare Locations = Locations + 1;
#end
#fclose Nodes
---------------------------------------------------
>>#declare _Type = array[Locations];
#declare _Location = array[Locations];
#declare _ID = array[Locations];
#declare _Latitude = array[Locations];
#declare _Longitude = array[Locations];
#declare _XYZ = array[Locations];

"" and i have problems to understand the block of codes above ""
-----------------------------------------------------------------


Post a reply to this message

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