コード例 #1
0
ファイル: planeHelper.py プロジェクト: shanlihou/pythonFunc
 def startGame(self):
     if len(self.players) == 1:
         self.players.append('computer')
     self.game = plane(len(self.players))
     ran = self.game.rollRan()
     img = [self.game.createFrame()]
     return img, '游戏开始,玩家列表:\n' + self.getPlayers() + '下一玩家:%s\n下一点数:%d' % (self.players[0], ran)
コード例 #2
0
  def _compute_plane(self):

    p0 = point.point(self._p1[0], self._p1[1], self._p1[2])
    p1 = point.point(self._p2[0], self._p2[1], self._p2[2])
    p2 = point.point(self._p3[0], self._p3[1], self._p3[2])

    self._down_plane = plane.plane(p0, p1, p2)

    p4 = point.point(self._p5[0], self._p5[1], self._p5[2])
    p6 = point.point(self._p7[0], self._p7[1], self._p7[2])
    p7 = point.point(self._p8[0], self._p8[1], self._p8[2])

    self._up_plane = plane.plane(p4, p6, p7)

    p0 = point.point(self._p1[0], self._p1[1], self._p1[2])
    p1 = point.point(self._p2[0], self._p2[1], self._p2[2])
    p5 = point.point(self._p6[0], self._p6[1], self._p6[2])

    self._left_plane = plane.plane(p0, p1, p5)

    p3 = point.point(self._p4[0], self._p4[1], self._p4[2])
    p6 = point.point(self._p7[0], self._p7[1], self._p7[2])
    p7 = point.point(self._p8[0], self._p8[1], self._p8[2])

    self._right_plane = plane.plane(p3, p6, p7)

    p1 = point.point(self._p2[0], self._p2[1], self._p2[2])
    p2 = point.point(self._p3[0], self._p3[1], self._p3[2])
    p6 = point.point(self._p7[0], self._p7[1], self._p7[2])

    self._back_plane = plane.plane(p1, p2, p6)

    p0 = point.point(self._p1[0], self._p1[1], self._p1[2])
    p3 = point.point(self._p4[0], self._p4[1], self._p4[2])
    p7 = point.point(self._p8[0], self._p8[1], self._p8[2])

    self._front_plane = plane.plane(p0, p3, p7)
コード例 #3
0
def step_impl(context):
    context.shape = plane()
コード例 #4
0
ファイル: heatsink.py プロジェクト: vargose/OpenSaber
D = 25.2
DEPTH_EPS = -1.0

R_HOLE = 8.92
D_HOLE = 4.4
D_INNER = 12.0

PLANE_XY = D + mat['tool_size']

# origin is at the center of the part

g = G(outfile='path.nc', aerotech_include=False, header=None, footer=None)
nomad_header(g, mat, CNC_TRAVEL_Z)
g.absolute()
g.move(z=0)
plane(g, mat, PLANE_DEPTH, -PLANE_XY / 2, -PLANE_XY / 2, PLANE_XY / 2,
      PLANE_XY / 2)

g.move(x=0, y=0)
g.move(z=-PLANE_DEPTH)

for r in range(6):
    theta = r * math.pi * 2.0 / 6.0
    x = math.cos(theta) * R_HOLE
    y = math.sin(theta) * R_HOLE

    g.move(z=PLANE_DEPTH + 1.0)
    g.move(x=x, y=y)
    g.move(z=PLANE_DEPTH)
    hole(g, mat, -H + DEPTH_EPS, d=D_HOLE)

g.move(z=PLANE_DEPTH + 1.0)
コード例 #5
0
ファイル: world_steps.py プロジェクト: natehouk/ray-tracer
def step_impl(context):
    context.upper = plane()
    context.upper.material.reflective = 1
    context.upper.material.transform = translation(0, 1, 0)
コード例 #6
0
from canvas import canvas_to_ppm
from material import material
from matrix import scaling, translation, view_transform
from plane import plane
from sphere import sphere
from tuple import color, point, point_light, vector
from world import world

if __name__ == "__main__":
    start = time.time()
    print("Starting render...")

    w = world()
    w.light = point_light(point(-10, 10, -10), color(1, 1, 1))

    floor = plane()
    floor.transform = scaling(10, 0.01, 10)
    floor.material.color = color(1, 0.9, 0.9)
    floor.material.specular = 0
    w.objects.append(floor)

    # left_wall = sphere()
    # left_wall.transform = translation(0, 0, 5) * rotation_y(-pi/4) * rotation_x(pi/2) * scaling(10, 0.01, 10)
    # left_wall.material = floor.material
    # w.objects.append(left_wall)

    # right_wall = sphere()
    # right_wall.transform = translation(0, 0, 5) * rotation_y(pi/4) * rotation_x(pi/2) * scaling(10, 0.01, 10)
    # right_wall.material = floor.material
    # w.objects.append(right_wall)
コード例 #7
0
from plane import plane
from sphere import sphere
from tuple import color, point, point_light, vector
from world import world

if __name__ == "__main__":
    start = time.time()
    print("Starting render...")

    w = world()
    w.light = point_light(point(-10, 10, -10), color(1, 1, 1))

    black = color(0, 0, 0)
    white = color(1, 1, 1)

    floor = plane()
    floor.transform = scaling(0.5, 0.5, 0.5)
    floor.material.color = color(0.9, 0.9, 0.9)
    floor.material.specular = 0.3
    floor.material.pattern = checkers_pattern(black, white)
    floor.material.reflective = 0.6
    w.objects.append(floor)

    left_wall = plane()
    left_wall.transform = (translation(0, 0, 5) * rotation_y(-pi / 4) *
                           rotation_x(pi / 2) * scaling(10, 0.01, 10))
    left_wall.material.specular = 0.7
    left_wall.material.pattern = stripe_pattern(black, white)
    w.objects.append(left_wall)

    right_wall = plane()
コード例 #8
0
ファイル: main.py プロジェクト: takitr/mycode
# -*- coding: utf-8 -*-
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *

import sphere
import camera
import plane
import sys

window = 0
sph = sphere.sphere(16, 16, 1)
camera = camera.camera()
plane = plane.plane(12, 12, 1., 1.)


def InitGL(width, height):
    glClearColor(0.1, 0.1, 0.5, 0.1)
    glClearDepth(1.0)
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    gluPerspective(45.0, float(width) / float(height), 0.1, 100.0)
    camera.move(0.0, 3.0, -5)


def DrawGLScene():
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glMatrixMode(GL_MODELVIEW)
    camera.setLookat()
    plane.draw()
コード例 #9
0
ファイル: interface.py プロジェクト: dssdassw/OldPythonWork
import random; from plane import plane; from functions import *
#Added a functional waiting list, 
hamilton = plane(500, 0, 20)
bahamas = plane(1000, -20, 5)
moscow = plane(1700, -5, 10)
print "HAMILTON FLIGHT SEATS:" + str(hamilton.seats) + "\nBAHAMAS FLIGHT SEATS:" + str(bahamas.seats) + "\nMOSCOW FLIGHT SEATS: " + str(moscow.seats)
choice = 0
notdone = True
print "Welcome to Toronto International Airport!"

while notdone:
	choice = choose("\n1. Book a flight\n2. Cancel a flight\n3. File a complaint\n4. Exit\n")
	if choice == 1:
		choice = choose("Book a flight to...\n1. Hamilton\n2. The Bahamas\n3. Moscow\n")
		if choice == 1:
			booking(hamilton)
		elif choice == 2:
			booking(bahamas)
		elif choice == 3:
			booking(moscow)
			
	if choice == 2:
		choice = choose("Cancel which flight?\n1. Hamilton\n2. The Bahamas\n3. Moscow\n")
		if choice == 1:
			if hamilton.booked: hamilton.cancel()
		elif choice == 2:
			if bahamas.booked: bahamas.cancel()
		elif choice == 3:
			if moscow.booked: moscow.cancel()
	
	if choice == 3:
コード例 #10
0
import sys
sys.path.append("../modules")

import plane
import point

import math

p1 = point.point(0.060167, -0.267595, -0.094069)
p2 = point.point(-0.029163, -0.510884, 1.967362)
p3 = point.point(-1.836883, 0.380311, 0.286389)

pA = plane.plane(p1, p2, p3)

p4 = point.point(0.060167, -0.267595, -0.094069)
p5 = point.point(2.036123, -0.514122, 0.052635)
p6 = point.point(-0.129902, -0.189737, -1.927521)

pB = plane.plane(p4, p5, p6)

angle = pA.return_angle(pB)
print angle, "rad ", 360.0 * (angle / math.pi), " grad"
コード例 #11
0
    trfCmplxFile = os.path.join(nuSIMPATH, '11-Parameters/nuSTORM-TrfLineCmplx-Params-v1.0.csv')
    print ("ftrfCmplxFile " , trfCmplxFile)
    print ("numSIMPATH, filename, rootfilename, trfCmplxFile \n", nuSIMPATH, "\n", filename, "\n", rootFilename,
         "\n", trfCmplxFile)
    outFilename = rootFilename
    logging.info("Parameters: %s,  \ntransfer line parameters: %s,  \noutput file: %s", filename,  trfCmplxFile, rootFilename)


# Get machine and run parameters
    nuStrt = nuPrdStrt.nuSTORMPrdStrght(filename)
    psLength = nuStrt.ProdStrghtLen()
    nuTrLnCmplx = nuTrfLineCmplx.nuSTORMTrfLineCmplx(trfCmplxFile)
    tlCmplxLength = nuTrLnCmplx.TrfLineCmplxLen()
    detectorPosZ = nuStrt.HallWallDist()
# set up the detector front face
    fluxPlane = plane.plane(psLength, detectorPosZ)
# set up the event history - instantiate
    eH = eventHistory.eventHistory()
    eH.outFile(outFilename)
# create the root structure to write to
    eH.rootStructure()
# initialise the python arrays to something sensible
    eH.makeHistory()

# event loop
for event in range(nEvents):
# generate a pion
    pi = piEvtInst.PionEventInstance(pionMom)
# set its values
    s = 0.0
    xl = 0.0
コード例 #12
0
class running: 
	'''Class to be passed into both threaded functions so they can communicate when to end mid-thread'''
	def __init__(self):
		self.running = False

if __name__ == '__main__':
	width = 1020
	height = 1020
	num_lines = 30
	depth = 400
	left_coordinates = create_coordinates('left', width, height, num_lines, depth)
	right_coordinates = create_coordinates('right', width, height, num_lines, depth)
	top_coordinates = create_coordinates('top', width, height, num_lines, depth)
	bottom_coordinates = create_coordinates('bottom', width, height, num_lines, depth)
	play = player(510, 925)
	map1 = plane(1, play, (0, 125, 125))
	map2 = plane(2, play, (0, 125, 125))
	map3 = plane(3, play, (125, 0, 125))
	map4 = plane(4, play, (125, 0, 125))
	map1.populate(10000, num_lines, 6)
	map2.populate(10000, num_lines, 6)
	map3.populate(10000, num_lines, 6)
	map4.populate(10000, num_lines, 6)
	r = running()
	try:
		faceThread = threading.Thread(target = read_frame, name = 'face', args = (r,))
		gameThread = threading.Thread(target = update, name = 'game', args = (left_coordinates, right_coordinates, bottom_coordinates, top_coordinates, map1, map2, map3, map4, play, num_lines, faceThread, r))
		gameThread.start()
		r.running = True
		faceThread.start()
		gameThread.join()
コード例 #13
0
import random
from plane import plane
from environment import environment
import logging
import time





if __name__ == "__main__":
  flying_machine1 = plane(0.9,"Boening 404")
  flying_machine2 = plane(0.5,"Unit Under Test 1")
  flying_machine3 = plane(0.0,"No Need Of Correction Plane")
  planes_under_test = [flying_machine1, flying_machine2, flying_machine3]

  period = 0.1
  time_stamps = 2000


  test_environment = environment(period,planes_under_test)

  file_logger = logging.getLogger("Data Logger")
  logging.basicConfig(filename='data.log',filemode='w', level=logging.INFO)

  print("Starting simulation\n")

  print("Logging simulation data, please wait...")
  env_info=[]
  for i in range(time_stamps):
コード例 #14
0
ファイル: world_steps.py プロジェクト: natehouk/ray-tracer
def step_impl(context):
    context.floor2 = plane()
    context.floor2.transform = translation(0, -1, 0)
    context.floor2.material.reflective = 0.5
    context.floor2.material.transparency = 0.5
    context.floor2.material.refractive_index = 1.5
コード例 #15
0
zlist2 = zlist[len(zlist) / 2:]
atoms2 = atoms[len(atoms) / 2:]

if len(nanaparticles) != 2:
    print "Only two nanoparticles can be used"
    exit(1)

DITS1 = 2.6
DIST2 = 12.6

nanop1 = nanaparticles[0]
ptop, pbot = nanop1.get_ptop_and_bottom()
l1 = line.line3d()
l1.set_two_point(ptop, pbot)
p1, p2, p3, p4 = nanop1.get_middle_points()
mdplane = plane.plane(p1, p2, p3)

group1_np1 = []
group2_np1 = []
group3_np1 = []
allnp1 = []

for i in range(len(xlist1)):
    p = point.point(xlist1[i], ylist1[i], zlist1[i])

    dist = mdplane.get_distance(p) * mdplane.check_point_side(p)
    if dist < DITS1:
        group1_np1.append((p.get_x(), p.get_y(), p.get_z()))
    elif dist >= DITS1 and dist < DIST2:
        group2_np1.append((p.get_x(), p.get_y(), p.get_z()))
    else:
コード例 #16
0
ファイル: nanoparticle.py プロジェクト: lstorchi/Stacker
    def project_point_101(self, pp):

        dist = float("inf")
        pret = point.point()
        peqn = plane.plane()

        p = self._UP_pright.project_point(pp)
        if (self.__is_in_polyhedra(0, p)):
            d = p.get_distance_from(pp)
            if (d < dist):
                dist = d
                pret = p
                peqn = self._UP_pright

        p = self._UP_pback.project_point(pp)
        if (self.__is_in_polyhedra(1, p)):
            d = p.get_distance_from(pp)
            if (d < dist):
                dist = d
                pret = p
                peqn = self._UP_pback

        p = self._UP_pleft.project_point(pp)
        if (self.__is_in_polyhedra(2, p)):
            d = p.get_distance_from(pp)
            if (d < dist):
                dist = d
                pret = p
                peqn = self._UP_pleft

        p = self._UP_pfront.project_point(pp)
        if (self.__is_in_polyhedra(3, p)):
            d = p.get_distance_from(pp)
            if (d < dist):
                dist = d
                pret = p
                peqn = self._UP_pfront

        p = self._DOWN_pright.project_point(pp)
        if (self.__is_in_polyhedra(5, p)):
            d = p.get_distance_from(pp)
            if (d < dist):
                dist = d
                pret = p
                peqn = self._DOWN_pright

        p = self._DOWN_pback.project_point(pp)
        if (self.__is_in_polyhedra(6, p)):
            d = p.get_distance_from(pp)
            if (d < dist):
                dist = d
                pret = p
                peqn = self._DOWN_pback

        p = self._DOWN_pleft.project_point(pp)
        if (self.__is_in_polyhedra(7, p)):
            d = p.get_distance_from(pp)
            if (d < dist):
                dist = d
                pret = p
                peqn = self._DOWN_pleft

        p = self._DOWN_pfront.project_point(pp)
        if (self.__is_in_polyhedra(8, p)):
            d = p.get_distance_from(pp)
            if (d < dist):
                dist = d
                pret = p
                peqn = self._DOWN_pfront

        return pret, peqn
コード例 #17
0
    def __compute_plane(self):

        # forse mi perdo i punti in superficie
        # molto liberamente ispirato a questo:
        # http://www.gamedev.net/topic/593430-finding-out-whether-a-point-is-in-a-frustum/
        # calcolo qui i piani che uso poi

        h1_p1 = point.point(self._x[0][0], self._x[0][1], self._x[0][2])
        h1_p2 = point.point(self._x[1][0], self._x[1][1], self._x[1][2])
        h1_p3 = point.point(self._x[2][0], self._x[2][1], self._x[2][2])
        h1_p4 = point.point(self._x[3][0], self._x[3][1], self._x[3][2])
        h1_p5 = point.point(self._x[4][0], self._x[4][1], self._x[4][2])
        h1_p6 = point.point(self._x[5][0], self._x[5][1], self._x[5][2])
        h1_p7 = point.point(self._x[6][0], self._x[6][1], self._x[6][2])
        h1_p8 = point.point(self._x[7][0], self._x[7][1], self._x[7][2])

        self._UP_pright = plane.plane(h1_p1, h1_p2, h1_p5)
        self._UP_pleft = plane.plane(h1_p3, h1_p4, h1_p8)
        self._UP_pbottom = plane.plane(h1_p1, h1_p2, h1_p3)
        self._UP_ptop = plane.plane(h1_p8, h1_p5, h1_p6)
        self._UP_pback = plane.plane(h1_p2, h1_p4, h1_p8)
        self._UP_pfront = plane.plane(h1_p1, h1_p3, h1_p5)

        h2_p1 = point.point(self._x[0][0], self._x[0][1], self._x[0][2])
        h2_p2 = point.point(self._x[1][0], self._x[1][1], self._x[1][2])
        h2_p3 = point.point(self._x[2][0], self._x[2][1], self._x[2][2])
        h2_p4 = point.point(self._x[3][0], self._x[3][1], self._x[3][2])
        h2_p5 = point.point(self._x[8][0], self._x[8][1], self._x[8][2])
        h2_p6 = point.point(self._x[9][0], self._x[9][1], self._x[9][2])
        h2_p7 = point.point(self._x[10][0], self._x[10][1], self._x[10][2])
        h2_p8 = point.point(self._x[11][0], self._x[11][1], self._x[11][2])

        self._DOWN_pright = plane.plane(h2_p1, h2_p2, h2_p6)
        self._DOWN_pleft = plane.plane(h2_p7, h2_p3, h2_p8)
        self._DOWN_pbottom = plane.plane(h2_p5, h2_p6, h2_p7)
        self._DOWN_ptop = plane.plane(h2_p4, h2_p1, h2_p2)
        self._DOWN_pback = plane.plane(h2_p6, h2_p2, h2_p4)
        self._DOWN_pfront = plane.plane(h2_p7, h2_p5, h2_p1)
コード例 #18
0
    def RunSim(self):
        print()
        print('Simulation.RunSim: simulation begins')
        print('-----------------')
        # Define root output stream
        runNumber = 26.0  # set run number
        # Define ntupleMaker called with run number; output file name; production straight data
        nt = ntM.ntupleMake(runNumber, self._nuStrt, self._rootfilename)
        if (nt.Version != 2.6):
            raiseException("Incorrect version of ntupleMaker")
# Define the distance of the downstream plane where the flux is calculated
#  parameters length of straight; distance from end of straight of plane.
        fluxPlane = plane.plane(self._nuStrt.ProdStrghtLen(),
                                self._nuStrt.HallWallDist())
        #KL! Hack        runType = self._nuStrt.runType()
        runType = 1
        iCnt = 0
        Scl = 1
        prt = 0
        #  generate Events - which depends on the run type
        #   1 is muon
        #   2 is pionFlash
        if (runType == 1):
            print(" ----> A muon run <---- \n")
            for iEvt in range(self._NEvt):
                if (iEvt % Scl) == 0:
                    iCnt += 1
                    print("    Generating event ", iEvt)
                    prt = 1
                    if iCnt == 10:
                        Scl = Scl * 10
                        iCnt = 0

#  Generate muon decay event
                nuEvt = nuEvtInst.NeutrinoEventInstance(self._pbeam)
                #  write to event branch
                nt.treeFill(nuEvt)
                #  Check intersection with downstream plane
                hitE, hitMu = fluxPlane.findHitPositionMuEvt(nuEvt)
                nt.fluxFill(hitE, hitMu)
                #   Fill some plots
                self._plots.fill(hitMu)
                if prt == 1:
                    prt = 0
                    print(nuEvt)
                    print("    End of this event simulation")
                    del (nuEvt)
#   2 pionFlash
        elif (runType == 2):
            print(" ----> A pion run <---- \n")
            for iEvt in range(self._NEvt):
                if (iEvt % Scl) == 0:
                    iCnt += 1
                    print("    Generating event ", iEvt)
                    prt = 1
                    if iCnt == 10:
                        Scl = Scl * 10
                        iCnt = 0
#  Generate a pi to mu+munu - given the central momentum of the pion beam
                piEvt = piEvtInst.PionEventInstance(self._pbeam)
                nt.pionTreeFill(piEvt)
                #  Look at the intersection with the detector plane
                hitMu = fluxPlane.findHitPositionPiEvt(piEvt)
                nt.flashFluxFill(hitMu)
                #  Fill some plots
                self._plots.fill(hitMu)
        else:
            print("Unrecognised run type ", runType, "  check ", self._nufile,
                  "\n")
            sys.exit("Unrecognised run type ")
        nt.closeFile()
        self._plots.histdo()
コード例 #19
0
def step_impl(context):
    context.p = plane()
コード例 #20
0
ファイル: woodcut.py プロジェクト: vargose/OpenSaber
mat = init_material(MAT)
g = G(outfile='path.nc',
      aerotech_include=False,
      header=None,
      footer=None,
      print_lines=False)
nomad_header(g, mat, H_STOCK + CNC_TRAVEL_Z)

g.absolute()
g.move(z=0)

if (H_STOCK < H_WOOD):
    raise RuntimeError("Stock can be the same as the wood, but not lower.")

if H_STOCK > H_WOOD:
    plane(g, mat, top, bounds.outer.x0, bounds.outer.y0, bounds.outer.x1,
          bounds.outer.y1)

g.move(z=top)

# cut the curve
hill(g, mat, D_OUTER, bounds.center.dx, bounds.center.dy)

#center bolt
HEAD = 7.0
HEAD_H = 4.0  # was 4.5 - go a little proud
BOLT = 4.3

travel(g, mat, x=bounds.cx)
hole(g, mat, bottom, d=BOLT)
hole(g, mat, -HEAD_H, d=HEAD)
コード例 #21
0
import sys
import math
from utility import *
from material import init_material
from rectangleTool import rectangleTool
from mecode import G
from hole import hole
from plane import plane

mat0 = init_material(sys.argv[1])
mat1 = init_material(sys.argv[2])

g = G(outfile='path.nc', aerotech_include=False, header=None, footer=None)
nomad_header(g, mat0, CNC_TRAVEL_Z)
g.absolute()
g.move(z=0)

plane(g, mat0, -2, 0, 0, 10, 10)

tool_change(g, mat1, 1)

g.move(x=2, y=2)
g.move(z=-2)
plane(g, mat1, -2, 0, 0, 6, 6)
コード例 #22
0
ファイル: field.py プロジェクト: matthew-truscott/qtcube
    def plotplane(self, iplane, res=0, interpolate=False):
        t0 = self.trans_point_to_space(iplane.p)
        tu = self.trans_point_to_space(iplane.u)
        tv = self.trans_point_to_space(iplane.v)
        tn = self.trans_point_to_space(iplane.n)
        nu = ul.normalize(tu)
        nv = ul.normalize(tv)
        tplane = plane.plane(p=t0, n=tn)
        nplane = plane.plane(p=t0, u=nu, v=nv)
        print("plane equation:", "pos", t0, "u vec", tu, "v vec", tv, "normal",
              tn)

        # now have the transformed equation of the plane
        # can think of cube as planes with boundaries
        # step 0: normalize direction vectors
        if res == 0:
            res = self.f_size[np.argmax(tu)]

        # step 1: take each cube plane and find intersections between planes

        # face 1: xy plane, z = 0
        c1n = np.array([0, 0, 1])
        c1p = np.array([0, 0, 0])
        c2n = np.array([0, 0, 1])
        c2p = np.array([0, 0, self.f_size[2]])
        c3n = np.array([0, 1, 0])
        c3p = np.array([0, 0, 0])
        c4n = np.array([0, 1, 0])
        c4p = np.array([0, self.f_size[1], 0])
        c5n = np.array([1, 0, 0])
        c5p = np.array([0, 0, 0])
        c6n = np.array([1, 0, 0])
        c6p = np.array([self.f_size[0], 0, 0])

        face1 = plane.plane(p=c1p, n=c1n)
        face2 = plane.plane(p=c2p, n=c2n)
        face3 = plane.plane(p=c3p, n=c3n)
        face4 = plane.plane(p=c4p, n=c4n)
        face5 = plane.plane(p=c5p, n=c5n)
        face6 = plane.plane(p=c6p, n=c6n)

        l1 = ul.plane_intersection(face1, tplane)
        l2 = ul.plane_intersection(face2, tplane)
        l3 = ul.plane_intersection(face3, tplane)
        l4 = ul.plane_intersection(face4, tplane)
        l5 = ul.plane_intersection(face5, tplane)
        l6 = ul.plane_intersection(face6, tplane)

        # step 2: are these intersections in the boundaries?
        (l1valid, l1pts) = self.has_line(l1)
        #print("line 1: ", l1pos, l1dir, "validity:", l1valid, l1pts)
        (l2valid, l2pts) = self.has_line(l2)
        #print("line 2: ", l2pos, l2dir, "validity:", l2valid, l2pts)
        (l3valid, l3pts) = self.has_line(l3)
        #print("line 3: ", l3pos, l3dir, "validity:", l3valid, l3pts)
        (l4valid, l4pts) = self.has_line(l4)
        #print("line 4: ", l4pos, l4dir, "validity:", l4valid, l4pts)
        (l5valid, l5pts) = self.has_line(l5)
        #print("line 5: ", l5pos, l5dir, "validity:", l5valid, l5pts)
        (l6valid, l6pts) = self.has_line(l6)
        #print("line 6: ", l6pos, l6dir, "validity:", l6valid, l6pts)

        # step 3: get a square in the basis of the plane that encompasses the intersection completely
        intersection_list = l1pts + l2pts + l3pts + l4pts + l5pts + l6pts
        if not intersection_list:
            sys.exit("no intersection possible")
        is_np = np.array(intersection_list)
        #print("intersection list = ", is_np)
        is_u = np.zeros((len(intersection_list)), dtype=float)
        is_v = np.zeros((len(intersection_list)), dtype=float)
        for i, val in enumerate(is_np):
            (is_u[i], is_v[i]) = ul.get_jk(nplane, val)

        # step 4: find the range of constants in the equation of the plane (v form)
        ##print("is_u", is_u, "is_v", is_v)
        umin = np.amin(is_u)
        umax = np.amax(is_u)
        vmin = np.amin(is_v)
        vmax = np.amax(is_v)

        # step 5: loop through points and perform interpolation if necessary
        urange = umax - umin
        vrange = vmax - vmin
        if vrange >= urange:
            vinc = vrange / res
            uinc = vinc
        else:
            uinc = urange / res
            vinc = uinc
        vni = int(math.ceil(vrange / vinc))
        uni = int(math.ceil(urange / uinc))
        data = np.zeros((uni, vni), dtype=float)
        for iu in np.arange(uni):
            for iv in np.arange(vni):
                dpos = np.array([0.1, 0.1, 0.1])
                ipos = t0 + (nu * (umin + (iu * uinc))) + (nv * (vmin +
                                                                 (iv * vinc)))
                if not interpolate:
                    ipos = np.rint(ipos)
                    if self.has_point(ipos + dpos):
                        #print(ipos)
                        data[iu, iv] = self.field[int(ipos[0]),
                                                  int(ipos[1]),
                                                  int(ipos[2])]
                    else:
                        data[iu, iv] = np.nan
                else:
                    dpos = dpos * 11
                    if self.has_point(ipos + dpos):
                        data[iu, iv] = self.interpolate(ipos)
                    else:
                        data[iu, iv] = np.nan

        plt.matshow(data, cmap='hot')
        plt.colorbar()
        #plt.show()
        return data
コード例 #23
0
import plane as pl
import RandomMachine
print("game start")
a = pl.plane()
p2 = RandomMachine.test()

a.startrecord('D:\data' + '/')
gamestate = 0
turning = "p1"
while gamestate == 0:
    a.print(data=a.p1919)
    if turning == "p1":
        a.checkemptydig(a.p1919, 1)
        gamestate = a.Humaninput(1)
        turning = 'p2'

    elif turning == "p2":
        p2.InputData__Available(a.checkemptydig(a.p1919, -1))

        gamestate = a.MachineInput(p2.resulty, p2.resultx, -1)
        turning = 'p1'

if gamestate == 1:
    print("p1 win________")
if gamestate == -1:
    print("p2 win________")
if gamestate == -2:
    print("ERROR")
if gamestate == 2:
    print("Draw")
a.closerecord()
コード例 #24
0
ファイル: world_steps.py プロジェクト: natehouk/ray-tracer
def step_impl(context):
    context.shape = plane()
    context.shape.material.reflective = 0.5
    context.shape.transform = translation(0, -1, 0)