6

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.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Sorfosh
  • 215
  • 1
  • 8
  • 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 – Lukas Lang Mar 05 '19 at 17:22

2 Answers2

10

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}}]

plane with vertical lines

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
halmir
  • 15,082
  • 37
  • 53
  • 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. – Sorfosh Mar 05 '19 at 19:18
  • 1
    @Sorfosh it works fine to me. Did you type sqrt instead Sqrt ? – halmir Mar 05 '19 at 20:23
  • oh... wow. I forgot it is case sensitive. Thank you! :P – Sorfosh Mar 05 '19 at 21:41
4

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

m_goldberg
  • 107,779
  • 16
  • 103
  • 257