TransWikia.com

Light rays within a cone

TeX - LaTeX Asked by icab on January 17, 2021

is there a possibility to create rays (lines) in the form of a cone at certain distances starting from a defined point? A manual creation via the respective coordinates seems to be too cumbersome, maybe via an iterating loop? The picture should look something like this:

enter image description here

Many thanks in advance and greetings

icab

2 Answers

My solution only works for a central point for now. I fill a rectangle(with a circle at the end) with an axial shading. To also rotate the shading, I use a canvas transform. This messes with the bounding box, -the reason for path (-8,-8) rectangle (8,8);

documentclass[tikz, border=1cm]{standalone}
begin{document}
begin{tikzpicture}
path (-8,-8) rectangle (8,8);
newcommand{golden}{180*(3-sqrt(5))};
foreach i in {50,...,1}{
    fill[left color=blue, right color=red!80!black, middle color=yellow, transform canvas={rotate= golden*i}] (0,0.05) rectangle ({sqrt(i)}, -0.05) ({sqrt(i)},0) circle[radius=0.3];
}
end{tikzpicture}
end{document}

enter image description here

Correct answer by hpekristiansen on January 17, 2021

If you accept a Metapost answer, this may be a starting point. Otherwise, I hope another user translate the example to TikZ or whatever else. You'll need --shell-escape enabled and Metapost installed (check mpost in Terminal or Command Prompt).

documentclass{article}
%Use --shell-escape or -enable-write18 
usepackage[shellescape,latex]{gmp}
begin{document}
begin{mpost}[name=nice]
%Define yellow just in case. ConTeXt does.
color yellow; yellow := (1, 1, 0);
numeric n, u; n := 100; u := 4mm;
%Helmut Vogel's formulas for sunflowers are a lazy, nice way to fill circles
numeric GoldenAngle; GoldenAngle := 180*(3-sqrt(5));
%Play changing "3u" to move the center.
pair Center, Points[]; Center := (left+up)*3u;
for i = 1 upto n:
    Points[i] := ((sqrt(i)*sind(GoldenAngle*i)), (sqrt(i)*cosd(GoldenAngle*i)))*u;
    draw Center -- (.25[Center,Points[i]]) withcolor blue;
    draw (.25[Center,Points[i]]) -- (.5[Center,Points[i]]) withcolor green;
         draw (.5[Center,Points[i]]) -- (.75[Center,Points[i]]) withcolor yellow;
    draw (.75[Center,Points[i]]) -- Points[i] withcolor red;
endfor
for i = 1 upto n:
    %Change "scaled ..." for larger or smaller dots.
    drawdot Points[i] withpen pencircle scaled 5 withcolor .5[red,black];
endfor
end{mpost}
begin{center}
usempost{nice}
end{center}
end{document}

enter image description here

Answered by Jairo A. del Rio on January 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP