本文整理汇总了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
}