R code for visualizing a reflective surface in 2d

Given that you have some reflective shape expressed in mathematical form the following code written in R will help you to visualize the effect of bouncing light (or potentially audio or any other object) off the surface of the object. It only calculates one bounce however and does not account for multiple reflections…perhaps sometime in the future. This script produces plots like the following:

A circular reflector.

A histogram of the y-intercepts of the reflected rays for a circular dish.

The following equations were used in producing the script. It was assumed that all light rays are directed from top to bottom and run parallel to the y axis. The output of the script is actually the y intercept values for the reflected rays. This may help to decide where sunlight would be most intensely focused for placing a heating element (if your application is solar concentration for heating) or a set of vertically placed pv units.

[tex=surface]f(x)[/tex] — the function that describes the 2d shape of the refelective surface.

[tex=surfacetan]f\prime (x)[/tex] — the first derivative of the shape function…gives the slope of the line tangent to the reflective surface.

[tex=tanline]y=f\prime (x_0) \cdot x+f(x_0)-f\prime (x_0)\cdot x_0[/tex] — the equation describing a line tangent to the reflective surface at a specified point on that surface.

[tex=tanperpline]y_p=m_p \cdot x + b_p[/tex] — the equation of the line perpendicular to the tangent line of the surface at a specified point on that surface.

[tex=tanperplinem]m_p=tan(2\cdot tan^{-1}(f\prime (x_0))-\frac{\pi}{2})[/tex]

[tex=tanperplineb]b_p=f(x_0)+m_p \cdot x_0[/tex]

To Run:

Please add your own reflective surface function and it’s derivative function, under the appropriate function names.

Usage:

reflectPlot(x, xline, fx, fxline, fpxline) — x = seq(a, b, by=increment), xline = seq(a, b, by=increment), fx = f(x), fxline = f(xline), fpxline = f’(xline)

x should be a sequence defined with a small increment to properly visualize the dish shape.

xline should be a sequence defined with a larger increment. It is used to create the reflection lines used to visualize the reflective surface.

Enjoy!

Share and Enjoy:
  • Digg
  • del.icio.us
  • Reddit
  • StumbleUpon
  • Technorati
  • Slashdot

No related posts.

Leave a Reply