MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Some basic Help



Jason asks for a way to generate random right triangles.

Jason, if this is more than just a toy, you need to be aware that the
word "random" doesn't mean anything by itself.  If you want to have a
random something, it has to be with respect to some given distribution.
So different solutions to your problem are going to behave differently,
because they will implicitly be based upon different distributions.

But just keeping it as a toy, here is one solution.  Choose random
lengths for the two legs and locate these on the positive x and y axes.
Then rotate the resulting triangle through a random angle and finally
translate it random amounts in the x and y directions. I will use the
normal distribution with mean 0 and variance 1 for the choice of
points.

<<Statistics`NormalDistribution.m`

r:=Random[NormalDistribution[0,1]]
rr:=Random[Real, 2N[Pi]]  (* for the angle *) rrr:=Random[Real] (* for
the gray level *)

randomRightTriangle:= Module[{angle=rr, translateVector = {r,r}},
{GrayLevel[rrr], Polygon[translateVector + #& /@ (
{{Cos[angle],-Sin[angle]},{Sin[angle],Cos[angle]}}.#& /@ 
{{0,0},{r,0},{0,r}})]}]

Show[Graphics[Table[randomRightTriangle,{10}]], AspectRatio->Automatic]


The set of all triangles in the plane is a six-dimensional manifold,
whereas the set of all right triangles in the plane is a
five-dimensional manifold:  first choose the hypotenuse by choosing
four real numbers; the vertex with the right angle lies on the circle
which has this hypotenuse as diameter, so you can specify it by just
choosing the angle. This suggests another solution (with a different
underlying distribution):

distance[{x0_, y0_}, {x1_, y1_}]:= Sqrt[(x0-x1)^2 + (y0-y1)^2] 

randomRightTriangle2:=Module[{
vertex1={r,r}, vertex2={r,r}, angle=rr, radius}, radius = .5
distance[vertex1, vertex2]; {GrayLevel[rrr], Polygon[{vertex1, vertex2,
  (vertex1+vertex2)/2 + radius {Cos[angle], Sin[angle]}}]}]

Show[Graphics[Table[randomRightTriangle2,{10}]], AspectRatio->Automatic]


It will be interesting to see some other solutions.


Will Self
Montana



  • Prev by Date: Knuth's Ln series doesn't work
  • Next by Date: Re: Some basic Help
  • Prev by thread: Some basic Help
  • Next by thread: Re: Some basic Help