Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // RandomInSemiSphere is a function to find a ray for diffuse reflection in semisphere.
- //
- // Parameters:
- // normal - the normal.
- //
- // Returns:
- // the vector.
- //
- func RandomInSemiSphere(normal utils.Vector) utils.Vector {
- random1 := rand.Float64()
- random2 := rand.Float64()
- v1 := utils.Vector{Coordinates: []float64{random1 + normal.Coordinates[0], -1 * normal.Coordinates[1], -1 * normal.Coordinates[2]}}
- v1 = utils.NormalizeVector(&v1)
- if utils.DotProduct(&normal, &v1) < 0 { // cos
- random1 = -1 * random1
- }
- v2 := utils.Vector{Coordinates: []float64{-1 * normal.Coordinates[0], random2 + normal.Coordinates[1], -1 * normal.Coordinates[2]}}
- v2 = utils.NormalizeVector(&v2)
- if utils.DotProduct(&normal, &v2) < 0 {
- random2 = -1 * random2
- }
- resultingVector := utils.Vector{Coordinates: []float64{normal.Coordinates[0] + random1, normal.Coordinates[1] + random2, normal.Coordinates[2]}}
- return resultingVector
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement