Application: RayTraceBounce
Revit Platform: All
Revit Version: 2011.0
First Released For: 2010.0
Programming Language: C#
Skill Level: Medium
Category: Geometry
Type: ExternalCommand

Subject: Ray Trace Bounce
Summary: 
This sample shows how to find intersection between ray and face and create connecting lines by Revit API method FindReferencesWithContextByDirection.

Classes: 
Autodesk.Revit.UI.IExternalCommand
Autodesk.Revit.DB.Document
Autodesk.Revit.DB.ElementSet
Autodesk.Revit.DB.GeometryObject

Project Files: 
Command.cs
This file contains the class Command that inherits from IExternalCommand. The class implements the Execute method and is used to show RayTraceBounceForm
RayTraceBounceForm.cs
The form allows entry of a coordinate location (X, Y, Z) within the model and a coordinate direction (i, j, k).

Description: 
This sample mostly uses the FindReferencesWithContextByDirection method for implementing the functionalities:
1.	Launch a ray from appointed location in appointed direction to find the first intersection with a face
2.	Calculate the reflection angle of the ray from the face and launch another ray to find the next intersection
3.	For each ray/intersection, create a model line connecting the two points.  The end result should be a series of model lines bouncing from item to item.
4.	Provide a hard limit of say, 100 intersections, to prevent endless reflections within an enclosed space.
5.	Write a log file of the intersection containing: the element type, id, and material of the intersected face.

Instructions:
1.	Open the document bounce.rvt which should have 3D view and a line style "bounce" created in the document
2.	Run this external command to show the dialog
3.	Input suitable origin point and direction and click ok button and the lines is created