本文整理匯總了Golang中github.com/runningwild/linear.Seg2.P方法的典型用法代碼示例。如果您正苦於以下問題:Golang Seg2.P方法的具體用法?Golang Seg2.P怎麽用?Golang Seg2.P使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/runningwild/linear.Seg2
的用法示例。
在下文中一共展示了Seg2.P方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestSeg
// Returns the fraction of the segment that was visible
func (l *Los) TestSeg(seg linear.Seg2) float64 {
seg.P = seg.P.Sub(l.in.Pos)
seg.Q = seg.Q.Sub(l.in.Pos)
wrap := len(l.in.Buffer.ZBuffer)
a1 := math.Atan2(seg.P.Y, seg.P.X)
a2 := math.Atan2(seg.Q.Y, seg.Q.X)
if a1 > a2 {
a1, a2 = a2, a1
seg.P, seg.Q = seg.Q, seg.P
}
if a2-a1 > math.Pi {
a1, a2 = a2, a1
seg.P, seg.Q = seg.Q, seg.P
}
start := int(((a1 / (2 * math.Pi)) + 0.5) * float64(len(l.in.Buffer.ZBuffer)))
end := int(((a2 / (2 * math.Pi)) + 0.5) * float64(len(l.in.Buffer.ZBuffer)))
count := 0.0
visible := 0.0
for i := start % wrap; i != end%wrap; i = (i + 1) % wrap {
dist2 := float32(rays[i].Isect(seg).Mag2())
if dist2 < l.in.Buffer.ZBuffer[i] {
visible += 1.0
}
count += 1.0
}
return visible / count
}
示例2: DrawSeg
func (l *Los) DrawSeg(seg linear.Seg2, source string) {
seg.P = seg.P.Sub(l.in.Pos)
seg.Q = seg.Q.Sub(l.in.Pos)
wrap := len(l.in.Buffer.ZBuffer)
a1 := math.Atan2(seg.P.Y, seg.P.X)
a2 := math.Atan2(seg.Q.Y, seg.Q.X)
if a1 > a2 {
a1, a2 = a2, a1
seg.P, seg.Q = seg.Q, seg.P
}
if a2-a1 > math.Pi {
a1, a2 = a2, a1
seg.P, seg.Q = seg.Q, seg.P
}
start := int(((a1 / (2 * math.Pi)) + 0.5) * float64(len(l.in.Buffer.ZBuffer)))
end := int(((a2 / (2 * math.Pi)) + 0.5) * float64(len(l.in.Buffer.ZBuffer)))
for i := start % wrap; i != end%wrap; i = (i + 1) % wrap {
dist2 := float32(rays[i].Isect(seg).Mag2())
// dist = rays[i].Isect(seg).Mag2()
if dist2 < l.in.Buffer.ZBuffer[i] {
l.in.Buffer.ZBuffer[i] = dist2
l.in.Buffer.SBuffer[i] = source
}
}
}
示例3: distFromPointToSeg
func distFromPointToSeg(p linear.Vec2, s linear.Seg2) float64 {
s.P = s.P.Sub(p)
s.Q = s.Q.Sub(p)
cross := s.Ray().Cross()
crossSeg := linear.Seg2{Q: cross}
if crossSeg.Left(s.P) != crossSeg.Left(s.Q) {
return s.DistFromOrigin()
}
da := s.P.Mag()
db := s.Q.Mag()
if da < db {
return da
}
return db
}