{"word_count": 583, "character_count": 5119}
Colored Lines of SightTo visualize the visibility of an individual facing in a certain direction, one can use lines of sight. "PColoredLinesOfSight3D" does so by selecting a point in space and a direction to "see". As rays are cast towards this point with a given aperture, the rays are colored in  function of their angular distance from the original line of sight; ie, the colors represent whether the ray is directly in the line of sight or at the periphery of the simulated vision.You can call the method in the ruby console :PColoredLinesOfSight3D.new(aperture, z0, rayLength, nbRays, colorMap, nbColorClasses)    .execWithArgs(pickedPoint, pickedFace, pickedEdge)We will first see how this method works on a signle point, then create our own batch process over multiple points: from one point of view looking at multiple directions, from multiple points looking at a single point, from multiple points looking at the same direction.AttributesInitializing PColoredLinesOfSight3D requires 6 attributes to run : the Aperture (in radians): the angle of vision, z0 : the height from the point of origin (eg: 1.60m for simulating the average eyelevel of someone standing, nbRays : the precision defined by the number of rays cast, colorMap : the selection of colors nbColorClasses : the number of classes for each level of apertureit is ran with the following arguments : pickedPoint : a Geom::Point3d object pickedFace : a Entities::cpoint (construction point) pickedEdge : a Entities::cline (construction line)Setting up Arguments :The first step is deciding on the point of view. If you know the coordinates of the point, set it up as such :anchorPoint = Geom::Point3d.new(885.m, 279.m, 2.7.m)If you have the location of a point on the ground (eg : derived from linear road data) and you wish to set the point of view above ground :viewpoint = Geom::Point3d.new(anchorPoint.x, anchorPoint.y, anchorPoint.z + 1.6.m)Otherwise, you can set up a z value directly within the PColoredLinesOfSight3D arguments, as explained below.Second, set up the target point :targetPoint = Geom::Point3d.new(83.m, 812.m, 145.m)Within a new layer, we will then derive construction points and lines from our 3D Points (refer to the SketchUp API for differences between ConstructionPoints and Point3d) and build construction lines which will serve as our "angle 0" or "direct lines of sight" between our two construction points :GeometricTransaction::startInADedicatedLayer("visibility")    cp = Sketchup.active_model.active_entities.add_cpoint(viewpoint)    shootingDir = Sketchup.active_model.active_entities.add_cline(viewpoint, targetPoint)GeometricTransaction::stop()[caption id="attachment_260" align="alignnone" width="300"] Construction Points and Construction Lines headed from the view points to the seen object in the "visibility" layer.[/caption]We're now ready to choose our LinesOfSight arguments, and run them over the selected points and viewing direction, for example:PColoredLinesOfSight3D.new(0.95, 0.m, 1000.m, 262144, LutLoader::LUTS[18], 3).execWithArgs(viewpoint, cp, shootingDir)meaning an aperture of 0.95 radians, 0 meters above the original point, with 1 km-long rays, with a ray count of 262144, using the color palette LutLoader::LUTS[18], and with three classes.Batch ProcessOne can modify the previous code to iterate over multiple points or multiple directions :Multiple points of view, using a sampled polyline. Views of the last story of a building from a linear street:anchorPoints = EntitiesListing.allConstructionPointsInLayer("SamplePathway_linelayer").each {|p|    anchorPoint = p.position    viewPoint = Geom::Point3d.new(anchorPoint.x, anchorPoint.y, anchorPoint.z + 10.cm)    targetPoint = EntitiesListing.allConstructionPointsInLayer("targetPoint")[0].position    GeometricTransaction::startInADedicatedLayer("visibility")    cp = Sketchup.active_model.active_entities.add_cpoint(viewPoint)    shootingDir = Sketchup.active_model.active_entities.add_cline(viewPoint, targetPoint)    GeometricTransaction::stop()PColoredLinesOfSight3D.new(2, 0.m, 1000.m, 262144, LutLoader::LUTS[18], 3).execWithArgs(viewPoint, cp, shootingDir)}[caption id="attachment_298" align="alignnone" width="500"] Result[/caption]Similarily, the inversed viewshed analysis where the viewPoint is the top floor of a skyscraper and the viewing directions are aimed at the nearby street :anchorPoints = EntitiesListing.allConstructionPointsInLayer("SamplePathway_linelayer").each {|p|    anchorPoint = p.position    viewPoint = Geom::Point3d.new(anchorPoint.x, anchorPoint.y, anchorPoint.z)    targetPoint = EntitiesListing.allConstructionPointsInLayer("targetPoint")[0].position    GeometricTransaction::startInADedicatedLayer("visibility")    cp = Sketchup.active_model.active_entities.add_cpoint(targetPoint)    shootingDir = Sketchup.active_model.active_entities.add_cline(targetPoint, viewPoint)    GeometricTransaction::stop()PColoredLinesOfSight3D.new(5, 0.m, 1000.m, 262144, LutLoader::LUTS[18], 5).execWithArgs(targetPoint, cp, shootingDir)}[caption id="attachment_297" align="alignnone" width="500"] Result[/caption]