3
$\begingroup$
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.

$\endgroup$
2
  • $\begingroup$ These seem related in concept if not application: (18034), (73522), (83636) $\endgroup$ Commented Apr 25, 2016 at 10:02
  • $\begingroup$ @Mr.Wizard Wow,Thanks for your links.I'll learn that one by one. $\endgroup$ Commented Apr 25, 2016 at 10:08

1 Answer 1

5
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$ Commented Apr 25, 2016 at 6:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.