简体   繁体   中英

Working with vectors, distances and graphs JAVA

I am working with vectors in graphs. The first part of the program generates a random position point of a vector on the graph. Next, I want the program to generate another random position point of a vector on the graph. How do I generate the second position vector, keeping in mind that the distance between both position vectors has to be 1?

  1. Randomize an angle x between 0 and 360 (or between 0 and 2*PI if you use radians).
  2. Add cos(x) to the x-value of the first random position point
  3. Add sin(x) to the y-value of the first random position point
  4. Profit :)

Why? Geometry. All the points on the circle (cos(x), sin(x)) are always 1 unit length away from its center.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM