// Shared by Mohsen Assaqqaf in a comment on The Building Coder:
        // https://thebuildingcoder.typepad.com/blog/2013/06/sun-direction-shadow-calculation-and-wizard-update.html#comment-4614771756
        // I found that this method for getting the vector
        // of the sun does not take into account the True
        // North angle of the project, so I updated it
        // myself using the following code:
        /// <summary>
        /// Get sun direction adjusted for project true north
        /// </summary>
        static XYZ GetSunDirection(View view)
        {
            Document doc = view.Document;

            // Get sun and shadow settings from the 3D View
            SunAndShadowSettings sunSettings
                = view.SunAndShadowSettings;

            // Set the initial direction of the sun at ground level (like sunrise level)
            XYZ initialDirection = XYZ.BasisY;

            // Get the altitude of the sun from the sun settings
            double altitude = sunSettings.GetFrameAltitude(
                sunSettings.ActiveFrame);

            // Create a transform along the X axis based on the altitude of the sun
            Transform altitudeRotation = Transform
                                         .CreateRotation(XYZ.BasisX, altitude);

            // Create a rotation vector for the direction of the altitude of the sun
            XYZ altitudeDirection = altitudeRotation
                                    .OfVector(initialDirection);

            // Get the azimuth from the sun settings of the scene
            double azimuth = sunSettings.GetFrameAzimuth(
                sunSettings.ActiveFrame);

            // Correct the value of the actual azimuth with true north

            // Get the true north angle of the project
            Element projectInfoElement
                = new FilteredElementCollector(doc)
                  .OfCategory(BuiltInCategory.OST_ProjectBasePoint)
                  .FirstElement();

            BuiltInParameter bipAtn
                = BuiltInParameter.BASEPOINT_ANGLETON_PARAM;

            Parameter patn = projectInfoElement.get_Parameter(
                bipAtn);

            double trueNorthAngle = patn.AsDouble();

            // Add the true north angle to the azimuth
            double actualAzimuth = 2 * Math.PI - azimuth + trueNorthAngle;

            // Create a rotation vector around the Z axis
            Transform azimuthRotation = Transform
                                        .CreateRotation(XYZ.BasisZ, actualAzimuth);

            // Finally, calculate the direction of the sun
            XYZ sunDirection = azimuthRotation.OfVector(
                altitudeDirection);

            return(sunDirection);
        }
Пример #2
0
        /// <summary>
        /// Description of ShadowCalculatorUtils.
        /// NOTE: this is derived from Scott Connover's great class "Geometry API in Revit" from DevCamp 2012, source files accesed 6-8-12 from here
        /// https://projectpoint.buzzsaw.com/_bz_rest/Web/Home/Index?folder=44#/_bz_rest/Web/Item/Items?folder=152&count=50&start=0&ownership=Homehttps://projectpoint.buzzsaw.com/_bz_rest/Web/Home/Index?folder=44#/_bz_rest/Web/Item/Items?folder=152&count=50&start=0&ownership=Home
        /// </summary>

        public static XYZ GetSunDirection(SunAndShadowSettings sunSettings)
        {
            //SunAndShadowSettings sunSettings = view.SunAndShadowSettings;

            XYZ initialDirection = XYZ.BasisY;

            //double altitude = sunSettings.Altitude;
            double altitude = sunSettings.GetFrameAltitude(sunSettings.ActiveFrame);

            Autodesk.Revit.DB.Transform altitudeRotation = Autodesk.Revit.DB.Transform.get_Rotation(XYZ.Zero, XYZ.BasisX, altitude);
            XYZ altitudeDirection = altitudeRotation.OfVector(initialDirection);

            //double azimuth = sunSettings.Azimuth;
            double azimuth       = sunSettings.GetFrameAzimuth(sunSettings.ActiveFrame);
            double actualAzimuth = 2 * Math.PI - azimuth;

            Autodesk.Revit.DB.Transform azimuthRotation = Autodesk.Revit.DB.Transform.get_Rotation(XYZ.Zero, XYZ.BasisZ, actualAzimuth);
            XYZ sunDirection    = azimuthRotation.OfVector(altitudeDirection);
            XYZ scaledSunVector = sunDirection.Multiply(100);

            return(scaledSunVector);
        }
Пример #3
0
        // Shared by Mohsen Assaqqaf in a comment on The Building Coder:
        // https://thebuildingcoder.typepad.com/blog/2013/06/sun-direction-shadow-calculation-and-wizard-update.html#comment-4614771756
        // I found that this method for getting the vector
        // of the sun does not take into account the True
        // North angle of the project, so I updated it
        // myself using the following code:
        /// <summary>
        /// Get sun direction adjusted for project true north
        /// </summary>
        static XYZ GetSunDirection(View view)
        {
            Document doc = view.Document;

            // Get sun and shadow settings from the 3D View

            SunAndShadowSettings sunSettings
                = view.SunAndShadowSettings;

            // Set the initial direction of the sun
            // at ground level (like sunrise level)

            XYZ initialDirection = XYZ.BasisY;

            // Get the altitude of the sun from the sun settings

            double altitude = sunSettings.GetFrameAltitude(
                sunSettings.ActiveFrame);

            // Create a transform along the X axis
            // based on the altitude of the sun

            Transform altitudeRotation = Transform
                                         .CreateRotation(XYZ.BasisX, altitude);

            // Create a rotation vector for the direction
            // of the altitude of the sun

            XYZ altitudeDirection = altitudeRotation
                                    .OfVector(initialDirection);

            // Get the azimuth from the sun settings of the scene

            double azimuth = sunSettings.GetFrameAzimuth(
                sunSettings.ActiveFrame);

            // Correct the value of the actual azimuth with true north

            // Get the true north angle of the project

            Element projectInfoElement
                = new FilteredElementCollector(doc)
                  .OfCategory(BuiltInCategory.OST_ProjectBasePoint)
                  .FirstElement();

            BuiltInParameter bipAtn
                = BuiltInParameter.BASEPOINT_ANGLETON_PARAM;

            Parameter patn = projectInfoElement.get_Parameter(
                bipAtn);

            double trueNorthAngle = patn.AsDouble();

            // Add the true north angle to the azimuth

            double actualAzimuth = 2 * Math.PI - azimuth + trueNorthAngle;

            // Create a rotation vector around the Z axis

            Transform azimuthRotation = Transform
                                        .CreateRotation(XYZ.BasisZ, actualAzimuth);

            // Finally, calculate the direction of the sun

            XYZ sunDirection = azimuthRotation.OfVector(
                altitudeDirection);

            // https://github.com/jeremytammik/the_building_coder_samples/issues/14
            // The resulting sun vector is pointing from the
            // ground towards the sun and not from the sun
            // towards the ground. I recommend reversing the
            // vector at the end before it is returned so it
            // points in the same direction as the sun rays.

            return(-sunDirection);
        }
Пример #4
0
        /// <summary>
        /// Description of ShadowCalculatorUtils.
        /// NOTE: this is derived from Scott Connover's great class "Geometry API in Revit" from DevCamp 2012, source files accesed 6-8-12 from here 
        /// https://projectpoint.buzzsaw.com/_bz_rest/Web/Home/Index?folder=44#/_bz_rest/Web/Item/Items?folder=152&count=50&start=0&ownership=Homehttps://projectpoint.buzzsaw.com/_bz_rest/Web/Home/Index?folder=44#/_bz_rest/Web/Item/Items?folder=152&count=50&start=0&ownership=Home
        /// </summary>
        public static XYZ GetSunDirection(SunAndShadowSettings sunSettings)
        {
            //SunAndShadowSettings sunSettings = view.SunAndShadowSettings;

            XYZ initialDirection = XYZ.BasisY;

            //double altitude = sunSettings.Altitude;
            double altitude = sunSettings.GetFrameAltitude(sunSettings.ActiveFrame);
            Autodesk.Revit.DB.Transform altitudeRotation = Autodesk.Revit.DB.Transform.get_Rotation(XYZ.Zero, XYZ.BasisX, altitude);
            XYZ altitudeDirection = altitudeRotation.OfVector(initialDirection);

            //double azimuth = sunSettings.Azimuth;
            double azimuth = sunSettings.GetFrameAzimuth(sunSettings.ActiveFrame);
            double actualAzimuth = 2 * Math.PI - azimuth;
            Autodesk.Revit.DB.Transform azimuthRotation = Autodesk.Revit.DB.Transform.get_Rotation(XYZ.Zero, XYZ.BasisZ, actualAzimuth);
            XYZ sunDirection = azimuthRotation.OfVector(altitudeDirection);
            XYZ scaledSunVector = sunDirection.Multiply(100);

            return scaledSunVector;
        }