Add DistanceToLine function
This commit is contained in:
		
							parent
							
								
									c1c166efcf
								
							
						
					
					
						commit
						1f04d688cf
					
				| @ -59,6 +59,21 @@ func Distance (start, end image.Point) float64 { | ||||
| 	return math.Sqrt(float64(delta.X * delta.X) + float64(delta.Y * delta.Y)) | ||||
| } | ||||
| 
 | ||||
| // DistanceToLine calculates the distance from a point to a line which passes | ||||
| // through points line1 and line2. | ||||
| func DistanceToLine (point, line1, line2 image.Point) float64 { | ||||
| 	x  := float64(point.X) | ||||
| 	y  := float64(point.Y) | ||||
| 	x1 := float64(line1.X) | ||||
| 	y1 := float64(line1.Y) | ||||
| 	x2 := float64(line2.X) | ||||
| 	y2 := float64(line2.Y) | ||||
| 	 | ||||
| 	triangle := math.Abs((y2 - y1)*x - (x2 - x1)*y + x2*y1 - y2*x1) | ||||
| 	 | ||||
| 	return triangle / Distance(line1, line2) | ||||
| } | ||||
| 
 | ||||
| func lerp (fac float64, x, y int) int { | ||||
| 	return int(float64(x) * fac + float64(y) * (1.0 - fac)) | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user