2
$\begingroup$

I'm creating a series of centered lines in {0,0} tilted from a set of angles.

The first angle is $30°$ and the last one is $110°$.

I want to control the number of lines between these two angles, but I can not use Subdivide because the angles are not evenly spaced.

The idea is that each angle has a relative proportion to the previous angle.

I did a test with $quant=20$:

ClearAll["Global`*"] quant = 20; ang = NestList[#*1.067121 &, 30, quant] p = FromPolarCoordinates[{5, # Degree}] &/@ ang // N; Graphics[{Line[{{0, 0}, #}] & /@ p}] 

Imagem1

And another test with $quant=10$:

ClearAll["Global`*"] quant = 10; ang = NestList[#*1.138747 &, 30, quant] p = FromPolarCoordinates[{5, # Degree}] &/@ ang // N; Graphics[{Line[{{0, 0}, #}] & /@ p}] 

Imagem2

In both codes I had to test the values $1.067121$ (First code) and $1.138747$ (Second code) to reach the last angle of $110°$.

Is there something in "NestList" that I can increase?

If you have another idea outside of that, it is also an option.

EDIT

I tried this and almost got it:

Solve[Last[NestList[#*coeff &,30,20]]==110,{coeff}]//N 
$\endgroup$
2
  • 2
    $\begingroup$ with Solve you should give the Reals domain argument, then select the positive result: Select[v /. Solve[Nest[#*v &, 30, 20] == 110, {v}, Reals], # > 0 &][[1]] // N $\endgroup$ Commented May 24, 2017 at 20:17
  • 2
    $\begingroup$ you can readily do this by hand though, with v = Exp[Log[110/30]/20] or even use ang = #1 Exp[Subdivide[#3] Log[#2/#1]] &[30, 110, 20] $\endgroup$ Commented May 24, 2017 at 20:31

3 Answers 3

1
$\begingroup$
ClearAll[fun] ; fun[num_,rad_:1] := Block[ {ang, poi, lin}, ang = N[Map[Function[Rescale[Slot[1],{1,num},{30,110}]]][Range[num]]] ; poi = Map[Function[First[CirclePoints[{rad,Slot[1] Degree},1]]],ang] ; lin = Map[Function[Line[{{0.,0.},Slot[1]}]],poi] ] ; Graphics[{Red,fun[2,1],Blue,fun[5,0.8],Green,fun[7,0.6]}] 

enter image description here

$\endgroup$
3
  • $\begingroup$ Image of output? $\endgroup$ Commented May 25, 2017 at 11:00
  • $\begingroup$ @MichaelE2, Done. Just noticed, this doesn't answer original question, sorry. Guess, this answer can be deleted. $\endgroup$ Commented May 25, 2017 at 11:12
  • $\begingroup$ Yeah, I was wondering if you got that. It's what I got, but sometimes there's an accidental mistake in the posted code. $\endgroup$ Commented May 25, 2017 at 11:24
3
$\begingroup$

So the answer is:

ClearAll["Global`*"] quant = 20; ang = NestList[#*Exp[Log[110/30]/quant] &, 30, quant] p = FromPolarCoordinates[{5, # Degree}] &/@ ang // N; Graphics[{Line[{{0, 0}, #}] & /@ p}] 
$\endgroup$
1
  • $\begingroup$ @MichaelE2 I already did that, but I posted it wrong at the moment $\endgroup$ Commented May 25, 2017 at 11:11
1
$\begingroup$

Another way:

Block[{quant = 20, a = 30., b = 110.}, ang = Exp[Log[a] + Log[b/a] Range[0., quant]/quant]; p = 5 Transpose@Through[{Cos, Sin}[ang Degree]]; lines = Transpose@ArrayReshape[p, Prepend[Dimensions@p, 2], 0.]; Graphics@Line@lines ] 

Mathematica graphics

Alternatives for ang and lines:

ang = Exp[Log[a] + Log[b/a] Range[0., quant]/quant] ang = a (b/a)^(Range[0., quant]/quant) ang = Array[Exp, quant + 1, Log@{a, b}] lines = Transpose@ArrayReshape[p, Prepend[Dimensions@p, 2], 0.] lines = Transpose[{ConstantArray[0., Dimensions@p], p}] lines = Transpose[{0. p, p}] 
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.