Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HW 6 & 7 Completed, Implemented Plots & Fixed Bug in subInsert() #16

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
35f6e42
Replacing jgoppert's Hw1 with my HW1 additions saved locally from a w…
cohen39 Sep 24, 2019
1e79d85
Renamed HW1 (delete/add operation) and added HW3
cohen39 Sep 24, 2019
2fdbbf4
Merge branch 'master' of github.com:jgoppert/aae497-f19
cohen39 Sep 30, 2019
1ade9d3
Merge branch 'master' of github.com:jgoppert/aae497-f19
cohen39 Oct 11, 2019
5b33523
Merge branch 'master' of github.com:jgoppert/aae497-f19
cohen39 Oct 11, 2019
7595354
Merge branch 'master' of github.com:jgoppert/aae497-f19
cohen39 Oct 11, 2019
7714251
Merge branch 'master' of github.com:jgoppert/aae497-f19
cohen39 Oct 13, 2019
ad50378
Merge branch 'master' of github.com:jgoppert/aae497-f19
cohen39 Oct 15, 2019
71a0c3a
Merge branch 'master' of github.com:jgoppert/aae497-f19
cohen39 Oct 19, 2019
20a7df2
Used casadi nlpsol to minimize time based on numerical integration us…
cohen39 Oct 20, 2019
cd22d54
Update README.md
cohen39 Oct 20, 2019
7bbd811
Create 7-Quad-Tree.py
cohen39 Oct 20, 2019
42d21fb
Completed Quad-Tree building, query, and plotting
cohen39 Oct 20, 2019
a8cb178
Implemented timeit and brute force
cohen39 Oct 20, 2019
9696724
Added hilighting of quads queryed in search, printing of times, and a…
cohen39 Oct 21, 2019
adf8fcf
Completed HW 6 by using for loop to build OF.
cohen39 Oct 24, 2019
1185633
Merge branch 'master' of github.com:jgoppert/aae497-f19
cohen39 Oct 29, 2019
9b255cf
Finished HW7
cohen39 Oct 29, 2019
0d5593c
Update quadtree.cpp
cohen39 Oct 29, 2019
f8c5dc2
Fixed bug in quadTree.cpp and implemented plotting of times vs resolu…
cohen39 Nov 2, 2019
501479a
Merge branch 'master' of github.com:cohen39/aae497-f19
cohen39 Nov 2, 2019
20b8a12
Merge branch 'master' of github.com:jgoppert/aae497-f19
cohen39 Nov 6, 2019
f4d3547
Merge branch 'master' of github.com:jgoppert/aae497-f19
cohen39 Nov 11, 2019
54573fb
Implemented level steady flight trim
cohen39 Nov 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# AAE497 Fall 2019 [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/jgoppert/aae497-f19/master) [<img src="https://jupyter.org/assets/main-logo.svg" height="20" title="JupyterLab">](https://mybinder.org/v2/gh/jgoppert/aae497-f19/master?urlpath=lab) [![nbviewer](https://img.shields.io/badge/view%20on-nbviewer-brightgreen.svg)](http://nbviewer.jupyter.org/github/jgoppert/aae497-f19/tree/master)
# AAE497 Fall 2019 [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/cohen39/aae497-f19/master) [<img src="https://jupyter.org/assets/main-logo.svg" height="20" title="JupyterLab">](https://mybinder.org/v2/gh/cohen39/aae497-f19/master?urlpath=lab) [![nbviewer](https://img.shields.io/badge/view%20on-nbviewer-brightgreen.svg)](http://nbviewer.jupyter.org/github/cohen39/aae497-f19/tree/master)

Class notebook.

Expand Down
58 changes: 0 additions & 58 deletions homework/1-F16-Pitch.ipynb

This file was deleted.

84 changes: 65 additions & 19 deletions homework/6-Casadi-Brach.ipynb

Large diffs are not rendered by default.

231 changes: 231 additions & 0 deletions homework/7-Quad-Tree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 20 14:51:58 2019

@author: cohen
"""

import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from random import random
from random import seed
import timeit

seed(4)

class Quad(object):
def __init__(self,left,right,down,up):
self.leftb = left
self.rightb = right
self.downb = down
self.upb = up
self.childQuads = [None,None,None,None]
self.particles = None

#Use this method to see which particles from any list of particles are enclosed by the quad.
def getPartsInQ(self,parts):
partsInQ = []
externParts = []
for aPart in parts:
if((aPart.xpos > self.leftb) and (aPart.xpos < self.rightb) and (aPart.ypos > self.downb) and (aPart.ypos < self.upb)):
partsInQ.append(aPart)
else:
externParts.append(aPart)

return externParts, partsInQ

def doesRectOverlap(self,rectLb,rectRb,rectDb,rectUb):
doesOverlap = not((self.rightb<rectLb)or(self.leftb>rectRb)or(self.upb<rectDb)or(self.downb>rectUb))
return doesOverlap

def isQuadEnclosed(self,rectLb,rectRb,rectDb,rectUb):
isEnclosed = (self.rightb<rectRb)and(self.leftb>rectLb)and(self.upb<rectUb)and(self.downb>rectDb)
return isEnclosed

class particle(object):
def __init__(self,x,y):
self.xpos = x
self.ypos = y

def buildQuadTree(quadBase,recurseCount):

leftOvParts = quadBase.particles
leftRightCent = quadBase.leftb + (quadBase.rightb - quadBase.leftb)/2
upDownCent = quadBase.downb + (quadBase.upb - quadBase.downb)/2

subQuad1 = Quad(quadBase.leftb, leftRightCent, upDownCent, quadBase.upb)
subQuad2 = Quad(leftRightCent, quadBase.rightb, upDownCent, quadBase.upb)
subQuad3 = Quad(quadBase.leftb, leftRightCent, quadBase.downb, upDownCent)
subQuad4 = Quad(leftRightCent, quadBase.rightb, quadBase.downb, upDownCent)

if leftOvParts != None:
leftOvParts, subQuad1.particles = subQuad1.getPartsInQ(leftOvParts)
if (subQuad1.particles != []) and (len(subQuad1.particles)>1) and (recurseCount < 500):
buildQuadTree(subQuad1,recurseCount+1)
quadBase.childQuads[0] = subQuad1

if leftOvParts != None:
leftOvParts, subQuad2.particles = subQuad2.getPartsInQ(leftOvParts)
if (subQuad2.particles != []) and (len(subQuad2.particles)>1) and (recurseCount < 500):
buildQuadTree(subQuad2,recurseCount+1)
quadBase.childQuads[1] = subQuad2

if leftOvParts != None:
leftOvParts, subQuad3.particles = subQuad3.getPartsInQ(leftOvParts)
if (subQuad3.particles != []) and (len(subQuad3.particles)>1) and (recurseCount < 500):
buildQuadTree(subQuad3,recurseCount+1)
quadBase.childQuads[2] = subQuad3
if leftOvParts != None:
leftOvParts, subQuad4.particles = subQuad4.getPartsInQ(leftOvParts)
if (subQuad4.particles != []) and (len(subQuad4.particles)>1) and (recurseCount < 500):
buildQuadTree(subQuad4,recurseCount+1)
quadBase.childQuads[3] = subQuad4

return

def plotQuadTree(quadBase):
if quadBase.childQuads[0] != None:
leftRightCent = quadBase.leftb + (quadBase.rightb - quadBase.leftb)/2
upDownCent = quadBase.downb + (quadBase.upb - quadBase.downb)/2

plt.plot([quadBase.leftb,quadBase.rightb],[upDownCent,upDownCent],'k')
plt.plot([leftRightCent,leftRightCent],[quadBase.downb,quadBase.upb],'k')

plotQuadTree(quadBase.childQuads[0])
plotQuadTree(quadBase.childQuads[1])
plotQuadTree(quadBase.childQuads[2])
plotQuadTree(quadBase.childQuads[3])

def plotQuadTreeSearchRegress(topQuad,rectLb,rectRb,rectDb,rectUb,ax):
if topQuad.doesRectOverlap(rectLb,rectRb,rectDb,rectUb):
if topQuad.isQuadEnclosed(rectLb,rectRb,rectDb,rectUb) or topQuad.childQuads[0]==None:
#good just return all of topQuad points (assuming it has them and that this has been checked?)
rect = matplotlib.patches.Rectangle([topQuad.leftb,topQuad.downb], topQuad.rightb - topQuad.leftb, topQuad.upb - topQuad.downb, angle=0.0,color='gray')
ax.add_patch(rect)

else:
#continue down the list for each quad
plotQuadTreeSearchRegress(topQuad.childQuads[0],rectLb,rectRb,rectDb,rectUb,ax)
plotQuadTreeSearchRegress(topQuad.childQuads[1],rectLb,rectRb,rectDb,rectUb,ax)
plotQuadTreeSearchRegress(topQuad.childQuads[2],rectLb,rectRb,rectDb,rectUb,ax)
plotQuadTreeSearchRegress(topQuad.childQuads[3],rectLb,rectRb,rectDb,rectUb,ax)

def plotQuadTreeSearch(topQuad,rectLb,rectRb,rectDb,rectUb):
fig,ax = plt.subplots(1)
plotQuadTreeSearchRegress(topQuad,rectLb,rectRb,rectDb,rectUb,ax)


def getPointsOfQuadOverlap(topQuad,rectLb,rectRb,rectDb,rectUb):
if topQuad.doesRectOverlap(rectLb,rectRb,rectDb,rectUb):
if topQuad.isQuadEnclosed(rectLb,rectRb,rectDb,rectUb) or topQuad.childQuads[0]==None:
#good just return all of topQuad points (assuming it has them and that this has been checked?)
return topQuad.particles

else:
#continue down the list for each quad
partList = []
partList = partList + getPointsOfQuadOverlap(topQuad.childQuads[0],rectLb,rectRb,rectDb,rectUb)
partList = partList + getPointsOfQuadOverlap(topQuad.childQuads[1],rectLb,rectRb,rectDb,rectUb)
partList = partList + getPointsOfQuadOverlap(topQuad.childQuads[2],rectLb,rectRb,rectDb,rectUb)
partList = partList + getPointsOfQuadOverlap(topQuad.childQuads[3],rectLb,rectRb,rectDb,rectUb)

return partList
else:
#dont get any of these points
return []

def getPtsCircQuadTree(topQuad,centX,centY,radius):
rectRb = centX + radius
rectLb = centX - radius
rectUb = centY + radius
rectDb = centY - radius
partCandidates = getPointsOfQuadOverlap(topQuad,rectLb,rectRb,rectDb,rectUb)

enclosedParts = []
for aPart in partCandidates:
dist = np.sqrt((aPart.xpos - centX)**2 + (aPart.ypos - centY)**2)
if dist<=radius:
enclosedParts.append(aPart)

return enclosedParts

def getPtsCircBrute(parts,centX,centY,radius):
enclosedParts = []
for aPart in parts:
dist = np.sqrt((aPart.xpos - centX)**2 + (aPart.ypos - centY)**2)
if dist<=radius:
enclosedParts.append(aPart)

return enclosedParts
#END CLASS AND HELPING METHOD DEFINITIONS----------------------------------------------
#BEGIN EVALUATION/"MAIN" CODE--------------------------------------------------

#Problem parameters
numParticles = 1000
particles = []
xlims = [0,60]
ylims = [0,30]
radius = 10
centX = 30
centY = 15
#------------------

#set particle positions
for i in range(0,numParticles-1):
particles.append(particle(random()*(xlims[1]-xlims[0])+xlims[0],random()*(ylims[1]-ylims[0])+ylims[0]))
#----------------------

#build Quad
def build_quad():
initialQuad = Quad(xlims[0],xlims[1],ylims[0],ylims[1])
initialQuad.particles = particles
buildQuadTree(initialQuad,0)
return initialQuad

t_build_quad = timeit.timeit(build_quad, number = 1)
print(t_build_quad)

initialQuad = build_quad()
#----------

#search Quad
def search_quad():
encParticles = getPtsCircQuadTree(initialQuad,centX,centY,radius)
return encParticles

t_search_quad = timeit.timeit(search_quad, number = 1)
print(t_search_quad)

encParticles = search_quad()
#-----------

#compute Brute
def search_brute():
return getPtsCircBrute(particles,centX,centY,radius)

t_search_brute = timeit.timeit(search_brute, number = 1)
print(t_search_brute)
#-------------

#plot Quadtree Visual
rectRb = centX + radius
rectLb = centX - radius
rectUb = centY + radius
rectDb = centY - radius
plotQuadTreeSearch(initialQuad,rectLb,rectRb,rectDb,rectUb)
plt.plot([particleX.xpos for particleX in particles], [particleY.ypos for particleY in particles],'.')
plotQuadTree(initialQuad)
plt.gca().set_aspect('equal', 'box')
circ = plt.Circle((centX, centY), radius, color='g', fill=False)
plt.gca().add_artist(circ)

plt.plot([particleX.xpos for particleX in encParticles], [particleY.ypos for particleY in encParticles],'r.')
plt.show()
#--------------------






Loading