def seg_intersect(line1, line2): a1, a2 = line1 b1, b2 = line2 da = geo2.Vec2Subtract(a2, a1) db = geo2.Vec2Subtract(b2, b1) dp = geo2.Vec2Subtract(a1, b1) dap = (-da[1], da[0]) denom = geo2.Vec2Dot(dap, db) if not denom: return False num = geo2.Vec2Dot(dap, dp) return geo2.Vec2Scale(geo2.Vec2Add(db, b1), num / denom)
def ScaleProbesAroundCenter(self): x, y = uicore.ScaleDpi(uicore.uilib.x), uicore.ScaleDpi(uicore.uilib.y) mousePos = geo2.Vector(x, y, 0) probeData = sm.GetService('scanSvc').GetProbeData() scannerWnd = form.Scanner.GetIfOpen() if scannerWnd is None: return probes = scannerWnd.GetProbeSpheres() centroid = geo2.Vector(0, 0, 0) numProbes = 0 for probeID, probeControl in probes.iteritems(): if probeID not in probeData or probeData[ probeID].state != const.probeStateIdle: continue probePos = probeControl.GetWorldPosition() centroid += probePos numProbes += 1 if numProbes <= 1: return centroid /= numProbes projectionParams = GetWorldToScreenParameters() centroidTansform = ((SYSTEMMAP_SCALE, 0, 0, 0), (0, SYSTEMMAP_SCALE, 0, 0), (0, 0, SYSTEMMAP_SCALE, 0), (centroid.x, centroid.y, centroid.z, 1.0)) screenCentroid = geo2.Vector( *ProjectTransform(projectionParams, centroidTansform)) screenCentroid.z = 0 probeScreenPos = geo2.Vector(*ProjectTransform( projectionParams, self.sr.movingProbe.locator.worldTransform)) probeScreenPos.z = 0 centerToProbe = probeScreenPos - screenCentroid centerToProbeLength = geo2.Vec2Length(centerToProbe) if centerToProbeLength < 0.1: return centerToProbeNormal = centerToProbe / centerToProbeLength toMouseDotProduct = geo2.Vec2Dot(mousePos - screenCentroid, centerToProbeNormal) projectedPos = screenCentroid + toMouseDotProduct * centerToProbeNormal toProjectedLength = geo2.Vec2Length(projectedPos - screenCentroid) if toProjectedLength < 0.1: return moveScale = toProjectedLength / centerToProbeLength if toMouseDotProduct < 0: moveScale = -moveScale for probeID, probeControl in probes.iteritems(): if probeID not in probeData or probeData[ probeID].state != const.probeStateIdle: continue pos = probeControl.GetWorldPosition() toProbe = pos - centroid endPos = centroid + toProbe * moveScale endPos = (endPos.x / SYSTEMMAP_SCALE, endPos.y / SYSTEMMAP_SCALE, endPos.z / SYSTEMMAP_SCALE) probeControl.SetPosition(endPos) scannerWnd.ShowCentroidLines() scannerWnd.HighlightProbeIntersections() sm.GetService('systemmap').HighlightItemsWithinProbeRange()
def closest_point_on_seg(seg_a, seg_b, circ_pos): seg_v = geo2.Vec2Subtract(seg_b, seg_a) pt_v = geo2.Vec2Subtract(circ_pos, seg_a) if geo2.Vec2Length(seg_v) <= 0: raise ValueError, 'Invalid segment length' seg_v_unit = geo2.Vec2Normalize(seg_v) proj = geo2.Vec2Dot(seg_v_unit, pt_v) if proj <= 0: return seg_a if proj >= geo2.Vec2Length(seg_v): return seg_b proj_v = geo2.Vec2Scale(seg_v_unit, proj) closest = geo2.Vec2Add(proj_v, seg_a) return closest
def GetMousePositionAngle(self): x, y = self.GetAbsolutePosition() x = uicore.uilib.x - x - self.radius y = uicore.uilib.y - y - self.radius v1 = (x, y) if geo2.Vec2Length(v1) < 5: return self._angle v2 = (0.0, 1.0) dot = geo2.Vec2Dot(v1, v2) cross = v1[0] * v2[1] - v1[1] * v2[0] angle = atan2(dot, cross) angle -= self.startAngle if angle < 0: angle += 2 * pi self._angle = angle return angle