Quote Originally Posted by Sallygreen
it would also work for a polygon yes??? as I need my code to geeneral for any geometry....but mainly for a polygon
Nope, it won't work for a general polygon. Generalizing it would seem to require a ton of linear algebra I'm not prepared to delve into, sorry . You could always tessellate your polygon with triangles and pick random points inside randomly chosen triangles. Then you wouldn't need a general method.

Quote Originally Posted by Sallygreen
I've done that
Code:
do i = 2,n
           do j = 2,m
              px(i,j)=x(1)+(1/i)*vx(1)+(1/j)*vx(2)
              py(i,j)=y(1)+(1/i)*vy(1)+(1/j)*vy(2)
          end do
      end do
wher vx(1) is the x coordinate of the v1=p2-p1, and so..... but it is not giving me the right answer....... I should be doing something wrong, but where is it??/
Since you seem to be using the square version, make sure your vertices p1, p2, and p3 are in consecutive order going either clockwise or counterclockwise around the square (p4 is unused; it's implied by the fact that we know 3 vertices and we're dealing with a square/parallelogram).

Ex: say the square is p1=(1, 1), p2=(2, 1), p3=(2, 2) [, p4=(1, 2)]. Then v1 = p2 - p1 = <1, 0>, v2 = p3 - p2 = <0, 1>. In your notation, vx(1) = 1, vy(1) = 0, vx(2) = 0, vy(2) = 1. Let's just say you want 15 points, and let's pick n = 6, m = 4 [you're looping from 2...n, 2...m for whatever reason, so the number of points generated is actually (n-1)(m-1)]. Say that we enter the loop when i = 4, j = 2. Then x1 = 1/i = 0.25, x2 = 1/j = 0.5. Using my formula, our random point is P = (1, 1) + 0.25*<1, 0> + 0.5*<0, 1> = (1.25, 1.5), which is definitely a good point.

Using your notation,

px(i,j) = px(4, 2) = x(1)+(1/i)*vx(1)+(1/j)*vx(2) = 1+0.25*1+0.5*0 = 1.25,
py(i,j) = py(4, 2) = y(1)+(1/i)*vy(1)+(1/j)*vy(2) = 1+0.25*0+0.5*1 = 1.5.


I never said these points would be uniformly distributed; they'll just be inside the square. Particularly using your code instead of randomly chosen points, you won't get anything close to a uniform distribution.