6
$\begingroup$

I am trying to generate around 10-20 points on the xy- plane in the domain $[-10,10]\times[-10,10]$ (in 3D) and I am having trouble. I want to draw the plane in 3D, graph the random (they do not have to be random but at least nicely dispersed) points, and then graph vertical lines through these points. I found this How to generate random points in a region? and tried to adopt it for a plane in 3D but since i am very new to Mathematica I cannot seem to make it work. I am aware of the RandomPoint command but the problem is i need to describe the region and I do not know how to describe the region of xy-plane. I tried z=0 but I think it only accepts "worded" regions.

Any help would be appreciated.

$\endgroup$
  • $\begingroup$ If you want to use RandomPoint, there's ImplicitRegion: RandomPoint[ ImplicitRegion[Abs@x < 10 && Abs@y < 10 && z == 0, {x, y, z}], 100] will give you 100 points in the specified region. Alternatively, you could also generate points in 2D using RandomReal[10,{100,2}] and add the z coordinate using Append[0]/@pts $\endgroup$ – Lukas Lang Mar 5 at 17:22
10
$\begingroup$

You can use RandomPoint with InfinitePlane and draw lines using InfiniteLine:

plane = InfinitePlane[{{0, 0, 0}, {1, 0, 0}, {0, 1, 0}}];
pts = RandomPoint[plane, 20, {{-10, 10}, {-10, 10}, {0, 0}}];

Graphics3D[{plane, Red, InfiniteLine[#, {0, 0, 1}] & /@ pts, Blue, 
  Sphere[pts, .1]}, PlotRange -> {{-10, 10}, {-10, 10}, {-5, 5}}]

enter image description here

$\endgroup$
  • $\begingroup$ Wow, that is perfect. Now if i wanted to change the direction vector of the line depending on the points, how would i do that? I tried changing $\{0,0,1\}$ to $\{\#[[2]], \#[[1]], sqrt[\#[[2]]^2 + \#[[1]]^2]\}$ but that didn't work. $\endgroup$ – Sorfosh Mar 5 at 19:18
  • 1
    $\begingroup$ @Sorfosh it works fine to me. Did you type sqrt instead Sqrt ? $\endgroup$ – halmir Mar 5 at 20:23
  • $\begingroup$ oh... wow. I forgot it is case sensitive. Thank you! :P $\endgroup$ – Sorfosh Mar 5 at 21:41
3
$\begingroup$

Maybe this will work for you.

First define a function for generating $n$ random points on the xy-plane.

pts[n_] := {#1, #2, 0} & @@@ RandomReal[{-10., 10.}, {n, 2}]

Then

SeedRandom[42];
Module[{n = 20, p0} ,
  p0 = pts[n];
  Graphics3D[
    {{AbsolutePointSize[4], Point[p0]},
     {Red, Thick, HalfLine[#, {0, 0, 1}] & /@ p0}},
    PlotRange -> {{-10, 10}, {-10, 10}, {0, 10}}]]

plot

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.