Re: Some basic Help
- To: mathgroup@smc.vnet.net
- Subject: [mg12371] Re: [mg12314] Some basic Help
- From: wself@viking.emcmt.edu (Will Self)
- Date: Sun, 10 May 1998 02:04:54 -0400
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