Guest User

Untitled

a guest
Oct 18th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.57 KB | None | 0 0
  1. Extr = {x /. #, y /. #} &;
  2. Att =
  3. Extr[
  4. NMinimize[{(x - #[[1]])^2 + (y - #[[2]])^2, x - x^3 + y^2 == 0}, {x, y}, AccuracyGoal -> 10, PrecisionGoal -> 8][[2]]] &;
  5.  
  6. DynamicModule[{loc1 = {0, 0}, pt1 = {0, 0}, pt2 = {1, 0}, loc2 = {1, 0}, pt3= {-1, 0}},
  7. {
  8. LocatorPane[Dynamic[{loc1, loc2}],
  9. ContourPlot[{y^2 - x (x - 1) (x + 1) == 0}, {x, -2, 2}, {y, -2, 2},
  10. AxesLabel -> Automatic, ImageSize -> 600,
  11. Epilog -> {Red, PointSize[Large],
  12. Point[Dynamic[pt1 = Att[loc1]]],
  13. Green,
  14. Point[Dynamic[pt2 = Att[loc2]]],
  15. Yellow, Thick,
  16. Dynamic[InfiniteLine[{pt1, pt2}]]
  17. }
  18. ]
  19. ],
  20. Dynamic[{pt1, pt2, pt3}];
  21. }
  22. ]
  23.  
  24. ecp = ContourPlot[y^2 == x (x - 1) (x + 1), {x, -2, 2}, {y, -2, 2}];
  25. ec = RegionNearest[ImplicitRegion[y^2 == x (x - 1) (x + 1), {{x, -2, 2}, {y, -2, 2}}]];
  26.  
  27. DynamicModule[{pts = {{-1, 0}, {1, 0}, {0, 0}}},
  28. Panel[Row[{LocatorPane[Dynamic[pts, (pts =
  29. Block[{ip = ec /@ Most[#], sol},
  30. sol = {[FormalX], [FormalY]} /.
  31. NSolve[{[FormalY]^2 == [FormalX]
  32. ([FormalX] - 1) ([FormalX] + 1),
  33. [FormalY] ==
  34. InterpolatingPolynomial[ip, [FormalX]]},
  35. {[FormalX], [FormalY]}];
  36. Append[ip, First[Pick[sol, Normalize[Chop[Min /@
  37. DistanceMatrix[sol, ip], 1.*^-6], Max], 1.]]]];) &],
  38. Show[ecp,
  39. Graphics[{{Yellow, Thick, Dynamic[InfiniteLine[Most[pts]]]},
  40. {PointSize[Large],
  41. {Red, Dynamic[Point[pts[[1]]]]},
  42. {Green, Dynamic[Point[pts[[2]]]]}},
  43. {PointSize[Medium], Brown, Dynamic[Point[pts[[3]]]]}}],
  44. ImageSize -> Medium], Appearance -> None],
  45. Pane[Dynamic[Grid[Transpose[{{Style["Point 1:", Red, Large],
  46. Style["Point 2:", Green, Large],
  47. Style["Point 3:", Brown, Large]},
  48. Style[#, Large] & /@ pts}]]]]}]]]
  49.  
  50. ecr = ImplicitRegion[y^2 == x (x - 1) (x + 1), {{x, -2, 2}, {y, -2, 2}}];
  51. BlockRandom[SeedRandom["elliptic"]; (* for reproducibility *)
  52. (* Quiet suppresses a few harmless error messages *)
  53. {p1, p2} = Quiet[RandomPoint[ecr, 2]];]
  54.  
  55. p3 = Chop[EllipticExp[EllipticLog[p1, {0, -1}] + EllipticLog[p2, {0, -1}], {0, -1}]];
  56.  
  57. ContourPlot[y^2 == x (x - 1) (x + 1), {x, -2, 2}, {y, -2, 2},
  58. Epilog -> {{Orange, {Thick, InfiniteLine[{p1, p2}]},
  59. {Dashed, Line[{{1, -1} p3, p3}]}},
  60. {PointSize[Large], {Red, Point[p1]}, {Green, Point[p2]}},
  61. {PointSize[Medium], Brown, Point[p3]}}]
  62.  
  63. Chop[Det[PadRight[{p1, p2, {1, -1} p3}, {3, 3}, 1]]]
  64. 0
  65.  
  66. ecp = ContourPlot[y^2 == x (x - 1) (x + 1), {x, -2, 2}, {y, -2, 2}];
  67. ec = RegionNearest[ImplicitRegion[y^2 == x (x - 1) (x + 1), {{x, -2, 2}, {y, -2, 2}}]];
  68.  
  69. DynamicModule[{pts = {{-1, 0}, {1, 0}, {0, 0}}},
  70. Panel[Row[{LocatorPane[Dynamic[pts, (pts =
  71. Block[{ip = ec /@ Most[#], sol},
  72. sol = {[FormalX], [FormalY]} /.
  73. NSolve[{[FormalY]^2 == [FormalX]
  74. ([FormalX] - 1) ([FormalX] + 1),
  75. [FormalY] ==
  76. InterpolatingPolynomial[ip, [FormalX]]},
  77. {[FormalX], [FormalY]}];
  78. Append[ip, First[Complement[sol, ip, SameTest->(Norm[#1-#2]<1*^-5&)]]]];) &],
  79. Show[ecp,
  80. Graphics[{{Yellow, Thick, Dynamic[InfiniteLine[Most[pts]]]},
  81. {PointSize[Large],
  82. {Red, Dynamic[Point[pts[[1]]]]},
  83. {Green, Dynamic[Point[pts[[2]]]]}},
  84. {PointSize[Medium], Brown, Dynamic[Point[pts[[3]]]]}}],
  85. ImageSize -> Medium], Appearance -> None],
  86. Pane[Dynamic[Grid[Transpose[{{Style["Point 1:", Red, Large],
  87. Style["Point 2:", Green, Large],
  88. Style["Point 3:", Brown, Large]},
  89. Style[#, Large] & /@ pts}]]]]}]]]
Add Comment
Please, Sign In to add comment