MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / Section

Function Section

math/geometry/straightlines.go:24–29  ·  view source on GitHub ↗

Section calculates the Point that divides a line in specific ratio. DO NOT specify the ratio in the form m:n, specify it as r, where r = m / n.

(p1, p2 *Point, r float64)

Source from the content-addressed store, hash-verified

22// Section calculates the Point that divides a line in specific ratio.
23// DO NOT specify the ratio in the form m:n, specify it as r, where r = m / n.
24func Section(p1, p2 *Point, r float64) Point {
25 var point Point
26 point.X = (r*p2.X + p1.X) / (r + 1)
27 point.Y = (r*p2.Y + p1.Y) / (r + 1)
28 return point
29}
30
31// Slope calculates the slope (gradient) of a line.
32func Slope(l *Line) float64 {

Callers 1

TestSectionFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestSectionFunction · 0.68