Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = 12; (* How many points *)
- pts = Table[RandomReal[], {n}, {2}];
- Show[
- Graphics[{Red, PointSize[0.01], Point[pts]}],
- ImageSize -> 8*72, PlotRange -> {{0, 1}, {0, 1}}, Frame -> True,
- FrameTicks -> False
- ]
- \[Theta]min = 89.0; (* Range of angles to be considered "right" (in \
- degrees) *)
- \[Theta]max = 91.0;
- RightAngles = {};
- Do[(
- ptA = pts[[i]];
- ptB = pts[[j]];
- ptC = pts[[k]];
- a = Norm[ptB - ptC];
- b = Norm[ptA - ptC];
- c = Norm[ptA - ptB];
- AngleA = 180/\[Pi] ArcCos[(b^2 + c^2 - a^2)/(2 b c)];
- If[\[Theta]min <=
- AngleA <= \[Theta]max, (AppendTo[RightAngles, {ptA, ptB, ptC}];
- Continue[];)];
- AngleB = 180/\[Pi] ArcCos[(a^2 + c^2 - b^2)/(2 a c)];
- If[\[Theta]min <=
- AngleB <= \[Theta]max, (AppendTo[RightAngles, {ptA, ptB, ptC}];
- Continue[];)];
- AngleC = 180/\[Pi] ArcCos[(a^2 + b^2 - c^2)/(2 a b)];
- If[\[Theta]min <= AngleC <= \[Theta]max,
- AppendTo[RightAngles, {ptA, ptB, ptC}]];
- ), {i, 1, n - 2}, {j, i + 1, n - 1}, {k, j + 1, n}]
- RightAngles (* Print the list of triples of vertices that form \
- "right-ish" triangles *)
- RightAngles // Length (* And how many there are *)
- (* Show the "right" triangles overlaid over the random points *)
- Show[
- Graphics[{Red, PointSize[0.02], Point[pts]}],
- Table[Graphics[{Thick, Hue[i/Length[RightAngles]],
- Line[{RightAngles[[i, 1]], RightAngles[[i, 2]],
- RightAngles[[i, 3]], RightAngles[[i, 1]]}]}], {i, 1,
- Length[RightAngles]}],
- ImageSize -> 8*72, Frame -> True, FrameTicks -> False,
- PlotRange -> {{0, 1}, {0, 1}}
- ]
- (* Create the list of unique side lengths in this set of triangles *)
- lengths = {};
- Do[(
- AppendTo[lengths, Norm[RightAngles[[i, 1]] - RightAngles[[i, 2]]]];
- AppendTo[lengths, Norm[RightAngles[[i, 1]] - RightAngles[[i, 3]]]];
- AppendTo[lengths, Norm[RightAngles[[i, 2]] - RightAngles[[i, 3]]]];
- ), {i, 1, Length[RightAngles]}];
- lengths = Union[lengths, lengths];
- (* Here is a set of "special" numbers to search for in ratios of \
- these lengths, along with their reciprocals *)
- nums = {\[Pi], E, EulerGamma, GoldenRatio, Sqrt[2], Sqrt[3], Sqrt[5],
- Sqrt[6], Sqrt[7], Sqrt[8], Sqrt[10]};
- (* Make a list of of side length ratios that "match" the above set of \
- special numbers *)
- f = 0.01; (* What fractional deviation from the "special" numbers is \
- acceptable *)
- Specials = {};
- Do[(
- r = lengths[[i]]/lengths[[j]];
- Do[(
- x = nums[[k]];
- If[Abs[(r - x)/x] <= f,
- AppendTo[
- Specials, {lengths[[i]], lengths[[j]], r, x, Abs[(r - x)/x]}]];
- If[Abs[(r - (1/x))/(1/x)] <= f,
- AppendTo[
- Specials, {lengths[[i]], lengths[[j]], r, 1/x,
- Abs[(r - (1/x))/(1/x)]}]];
- ), {k, 1, Length[nums]}]
- ), {i, 1, Length[lengths]}, {j, 1, Length[lengths]}];
- Specials (* Print the list of "special" side length relationships and \
- how accurate they are *)
- Specials // Length
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement