3
SeedRandom[8]
plot = ParametricPlot[
  Evaluate@BezierFunction[temPoint = RandomReal[{-50, 50}, {5, 2}]][
    t], {t, 0, 1}, AxesOrigin -> {0, 0}]

Mathematica graphics

We can hightlight a random point in this graphics.

SeedRandom[3]
Show[plot, 
 Epilog -> {Red, AbsolutePointSize[10], 
   Point[randomPoint = 
     RandomReal /@ RegionBounds@DiscretizeGraphics[plot]]}]

Mathematica graphics

We can change the plot to image.

Image[plot]

Then its coordinate system will be a image coordinate system.To guarantee the randomPoint be the original graphics' position in the new coordinate system,I use RescalingTransform try to implement this target.

HighlightImage[
 Image[plot], {Red, PointSize[.03], 
  Point[RescalingTransform[
     First@Values[AbsoluteOptions[plot, PlotRange]], 
     Transpose[{{0, 0}, ImageDimensions@Image[plot]}]]@randomPoint]}]

Mathematica graphics

But as you see,there is a error in this method obviously.

yode
  • 26,686
  • 4
  • 62
  • 167

1 Answers1

5

This isn't elegant, but I think it should work pretty reliably.

Start with the base plot:

plot = ParametricPlot[
  Evaluate@BezierFunction[temPoint = RandomReal[{-50, 50}, {5, 2}]][
    t], {t, 0, 1}, AxesOrigin -> {0, 0}]

Create a version that has the point, but wrap the point in Annotation, with type "Region":

plot2 = Show[plot, 
  Epilog -> {Red, AbsolutePointSize[10], 
    Annotation[
     Point[randomPoint = 
       RandomReal /@ RegionBounds@DiscretizeGraphics[plot]], "Point", 
     "Region"]}]

Rasterize the second one, and extract the regions, converting to the center of the point:

{px, py} = Mean[{"Point", "Region"} /. Rasterize[plot2, "Regions"]];

Convert the main plot to an image:

image = Image[plot];

Get the dimensions of the image:

{ix, iy} = ImageDimensions[image];

Highlight the image, keeping in mind that the region annotations use a coordinate system that is flipped vertically from the usual one used by Image:

HighlightImage[
 Image[plot], {Red, PointSize[.03], Point[{px, iy - py}]}]

enter image description here

Brett Champion
  • 20,779
  • 2
  • 64
  • 121
  • Wow.It's a surprise to me about the Rasterize can do this.Just a little suggestion for Point[{px, iy - py}] should be Point[{px-0.5, iy - py-0.5}] or I miss something. – yode Apr 25 '16 at 06:00