Exemple #1
0
def is_contain(query_point, vertex_lst):
  if len(vertex_lst) == 4:
    vertex_box = copy.deepcopy(vertex_lst)
    vertex_box = clockwise_sort(vertex_box)
    polygon = Polygon(vertex_box)
  else:
    polygon = Polygon(vertex_lst)
  point = Point(query_point[0], query_point[1])
  if not polygon.is_convex:
    return False
  return polygon.contains_point(point)
Exemple #2
0
def is_contain(query_point, vertex_lst):
    if len(vertex_lst) == 4:
        vertex_box = copy.deepcopy(vertex_lst)
        vertex_box = clockwise_sort(vertex_box)
        polygon = Polygon(vertex_box)
    else:
        polygon = Polygon(vertex_lst)
    point = Point(query_point[0], query_point[1])
    if not polygon.is_convex:
        return False
    return polygon.contains_point(point)
 def get_image_polygon(obj):
     minps = PointStamped()
     minps.header.stamp = rospy.Time(0)
     minps.header.frame_id = 'base_footprint'
     minps.point.x = obj.points[0].y
     minps.point.y = -obj.points[0].x
     minps.point.z = obj.points[0].z
     
     minp = self.tf.transformPoint('kinect_rgb_optical_frame', minps).point
     
     minps.point.x = obj.points[1].y
     minps.point.y = -obj.points[1].x
     minps.point.z = obj.points[1].z
     
     maxp = self.tf.transformPoint('kinect_rgb_optical_frame', minps).point
     
     ct = np.array( [(minp.x,minp.y,minp.z), (maxp.x,minp.y,minp.z), (maxp.x,maxp.y,maxp.z), (minp.x,maxp.y,maxp.z)] )
     corners = cv.fromarray(ct)
     out = cv.fromarray(np.zeros((4,2)))
     cam_mat = np.array( [(525, 0, 319.5), (0, 525, 239.5), (0, 0, 1)] )
     cv.ProjectPoints2(corners,
                       cv.fromarray(np.zeros((1,3))),
                       cv.fromarray(np.zeros((1,3))),
                       cv.fromarray(cam_mat),
                       cv.fromarray(np.zeros((1,4))),
                       out)
     
     vs = []
     for l in np.asarray(out):
         vs.append( Vec2(*l) )
     
     return Polygon(vs)
Exemple #4
0
def convex_hull(data):
    BoundingBoxes = [o.representation.rect for o in data]
    polys = []
    for b in BoundingBoxes:
        polys.append(b.to_polygon())
    points = [] 
    for p in polys:
        output = [i for i in p]
        points = points + output
    hullpoly = Polygon.convex_hull(points)
    hullpoints = []
    for p in hullpoly:
        hullpoints.append(p)
    return hullpoints
def good_polygon(xs,ys,min_area, min_line):
    
    #checking area
    area = 0.5*np.abs(np.dot(xs,np.roll(ys,1))-np.dot(ys,np.roll(xs,1)))
    if area<min_area:
        return False
    
    #checking if is simples
    poly = Polygon(zip(xs,ys))
    if not poly.is_simple:
        return False
    
    #checking if is convex
    if not poly.is_convex:
        return False

    #checking lines size
    distances = np.sqrt( (xs[1:]-xs[:-1])**2 + (ys[1:]-ys[:-1])**2 )
    if distances.min() < min_line:
        return False

    return True
Exemple #6
0
def poly_from_dict(dikt):
    return Polygon.from_points([vec2_from_dict(v) for v in dikt['points']])
Exemple #7
0
 def region(self) -> Polygon:
     return Polygon([
         *self.left_wall.line_segment.points,
         *reversed(self.right_wall.line_segment.points),
     ])
Exemple #8
0
poly_Manhattan = Polygon([
        (40.700292, -74.010773),
        (40.707580, -73.999271),
        (40.710443, -73.978758),
        (40.721762, -73.971977),
        (40.729568, -73.971291),
        (40.733503, -73.973994),
        (40.746834, -73.968072),
        (40.775114, -73.941936),
        (40.778884, -73.942580),
        (40.781906, -73.943589),
        (40.785351, -73.939362),
        (40.789640, -73.936272),
        (40.793149, -73.932238),
        (40.795228, -73.929491),
        (40.801141, -73.928976),
        (40.804877, -73.930907),
        (40.810496, -73.934298),
        (40.834074, -73.934383),
        (40.855371, -73.922281),
        (40.870690, -73.908892),
        (40.878348, -73.928289),
        (40.851151, -73.947258),
        (40.844074, -73.947086),
        (40.828229, -73.955498),
        (40.754019, -74.008713),
        (40.719941, -74.013863),
        (40.718575, -74.013605),
        (40.718802, -74.017038),
        (40.704977, -74.020042),
        (40.700553, -74.016438)
        ])
        #       with open('AllList.txt', 'w') as f_ff:
        #           f_ff.write(json.dumps(AllList))

        if os.path.isfile('PolyList.txt'):
            with open('PolyList.txt', 'w') as f_f:
                f_f.write(json.dumps(PolyList))
        else:
            with open('PolyList.txt', 'w') as f_f:
                f_f.write(json.dumps(PolyList))

from planar import Polygon
innerPolyList = []
for f in PolyList:
    for d in PolyList:
        if d != f:
            polyg = Polygon(d)
            if polyg.contains_point(f[0]):
                innerPolyList.append(f)
#print(innerPolyList)
#Get alist of External Polygons only
PolyListNoInner = []
for dd in PolyList:
    if dd not in innerPolyList:
        PolyListNoInner.append(dd)

print("len polylistNoInner", len(PolyListNoInner))

from shapely.geometry import Polygon
# get a list on polygon areas and the index in its ExternPoly
polyArea = []
for jj in range(len(PolyListNoInner)):
Exemple #10
0
poly_1 = Polygon([(6.86687, 53.4343), (6.90056, 53.3518), (6.90577, 53.3505),
                  (6.93002, 53.3401), (6.9319, 53.3376), (6.9367, 53.3354),
                  (6.94166, 53.3307), (6.94858, 53.3261), (6.98015, 53.3198),
                  (7.02003, 53.3061), (7.03777, 53.3096), (7.04623, 53.3039),
                  (7.05828, 53.3019), (7.07008, 53.3039), (7.07862, 53.3096),
                  (7.08546, 53.3096), (7.08546, 53.3028), (7.07748, 53.2987),
                  (7.0735, 53.2956), (7.07374, 53.2913), (7.07862, 53.2829),
                  (7.08074, 53.2668), (7.11109, 53.2563), (7.18336, 53.2451),
                  (7.19459, 53.245), (7.19747, 53.2166), (7.19851, 53.2006),
                  (7.19541, 53.185), (7.18858, 53.1678), (7.17442, 53.1458),
                  (7.17194, 53.1377), (7.17267, 53.1258), (7.17649, 53.1194),
                  (7.18135, 53.1142), (7.18507, 53.1054), (7.19437, 53.0338),
                  (7.19282, 52.998), (7.18362, 52.9661), (7.16192, 52.9326),
                  (7.07986, 52.8544), (7.07215, 52.8413), (7.06198, 52.824),
                  (7.0533, 52.7906), (7.04399, 52.6826), (7.03666, 52.6474),
                  (7.01847, 52.626), (6.98281, 52.6328), (6.96772, 52.6367),
                  (6.91842, 52.6322), (6.8654, 52.642), (6.77052, 52.641),
                  (6.73704, 52.6347), (6.71908, 52.6268), (6.70179, 52.6191),
                  (6.71016, 52.6087), (6.7082, 52.5997), (6.70365, 52.5914),
                  (6.70396, 52.5831), (6.71099, 52.5766), (6.74375, 52.5597),
                  (6.68825, 52.5426), (6.67172, 52.5417), (6.68402, 52.526),
                  (6.68753, 52.5081), (6.68898, 52.4905), (6.69507, 52.4756),
                  (6.71481, 52.4616), (6.74117, 52.4537), (6.82034, 52.4468),
                  (6.87201, 52.4347), (6.90023, 52.4319), (6.92648, 52.433),
                  (6.95149, 52.4375), (6.96079, 52.4428), (6.967, 52.4496),
                  (6.9733, 52.4514), (7.03417, 52.3908), (7.04823, 52.3651),
                  (7.03976, 52.3286), (7.01971, 52.3), (7.01247, 52.2849),
                  (7.01185, 52.2666), (7.02074, 52.2453), (7.0266, 52.2386),
                  (7.02911, 52.2358), (7.02632, 52.2306), (6.98188, 52.214),
                  (6.97113, 52.2063), (6.94767, 52.1828), (6.92772, 52.1719),
                  (6.88483, 52.1603), (6.8654, 52.1478), (6.84328, 52.12),
                  (6.83067, 52.1129), (6.77158, 52.1088), (6.76587, 52.1084),
                  (6.74985, 52.1029), (6.7329, 52.092), (6.72763, 52.0863),
                  (6.71947, 52.0736), (6.7114, 52.0673), (6.69941, 52.0636),
                  (6.68887, 52.0631), (6.67988, 52.0605), (6.67296, 52.0501),
                  (6.67502, 52.0348), (6.69094, 52.0279), (6.71285, 52.0239),
                  (6.77817, 52.0013), (6.80401, 51.9844), (6.80918, 51.9795),
                  (6.81166, 51.9728), (6.81073, 51.9606), (6.80566, 51.9575),
                  (6.79801, 51.9567), (6.78985, 51.9511), (6.76701, 51.9255),
                  (6.74375, 51.9083), (6.71667, 51.8993), (6.62815, 51.8975),
                  (6.52862, 51.8764), (6.47943, 51.853), (6.46289, 51.8484),
                  (6.44253, 51.8484), (6.37845, 51.8601), (6.38662, 51.8376),
                  (6.38248, 51.8276), (6.34497, 51.8211), (6.34197, 51.8367),
                  (6.32574, 51.8425), (6.2874, 51.8462), (6.28285, 51.8496),
                  (6.27179, 51.8619), (6.26466, 51.8662), (6.25639, 51.8668),
                  (6.22518, 51.8625), (6.19138, 51.8712), (6.15924, 51.8873),
                  (6.127, 51.8967), (6.09299, 51.8853), (6.10539, 51.8795),
                  (6.1427, 51.8552), (6.15614, 51.8421), (6.14002, 51.8445),
                  (6.11645, 51.8483), (6.084, 51.8537), (6.04328, 51.8469),
                  (6.02891, 51.8421), (6.00824, 51.8326), (5.98892, 51.8275),
                  (5.94809, 51.823), (5.93145, 51.8156), (5.92804, 51.8067),
                  (5.95078, 51.7959), (5.96411, 51.7766), (5.96235, 51.7564),
                  (5.94606, 51.7463), (5.94013, 51.7426), (5.93931, 51.7319),
                  (5.94923, 51.7294), (5.97827, 51.7298), (5.98974, 51.7264),
                  (6.01207, 51.7159), (6.02199, 51.7095), (6.00855, 51.6812),
                  (6.0315, 51.663), (6.09919, 51.6445), (6.08751, 51.6221),
                  (6.08214, 51.6078), (6.08648, 51.5955), (6.15304, 51.5384),
                  (6.19335, 51.5093), (6.20048, 51.4766), (6.20534, 51.4584),
                  (6.20172, 51.4386), (6.19407, 51.4174), (6.19273, 51.399),
                  (6.20782, 51.3877), (6.20203, 51.3789), (6.19893, 51.357),
                  (6.19355, 51.3445), (6.18363, 51.3357), (6.15821, 51.3246),
                  (6.14777, 51.3182), (6.09651, 51.2588), (6.07542, 51.2427),
                  (6.06519, 51.2316), (6.05661, 51.2117), (6.05372, 51.1894),
                  (6.06085, 51.1709), (6.08431, 51.1627), (6.13413, 51.1842),
                  (6.15707, 51.1793), (6.14911, 51.1763), (6.12627, 51.1646),
                  (6.14725, 51.1523), (6.13237, 51.1398), (6.07542, 51.1204),
                  (5.98292, 51.0747), (5.96949, 51.0649), (5.95026, 51.0395),
                  (5.93796, 51.0309), (5.91957, 51.0297), (5.90623, 51.0374),
                  (5.89435, 51.0471), (5.8805, 51.0521), (5.85249, 51.0428),
                  (5.85817, 51.0193), (5.87357, 50.9906), (5.87461, 50.9654),
                  (5.88825, 50.9671), (5.91419, 50.9752), (5.92773, 50.9777),
                  (5.94158, 50.9765), (5.96783, 50.971), (6.0037, 50.9737),
                  (6.00576, 50.9685), (5.99966, 50.9601), (5.99584, 50.9518),
                  (5.99729, 50.9374), (5.99987, 50.9294), (6.00752, 50.9241),
                  (6.03108, 50.9147), (6.06374, 50.9075), (6.06178, 50.9035),
                  (6.05651, 50.8981), (6.05465, 50.8915), (6.06312, 50.8709),
                  (6.06281, 50.8629), (6.05672, 50.8527), (6.04555, 50.8442),
                  (6.02302, 50.8454), (6.00928, 50.8405), (6.00049, 50.8304),
                  (6.00142, 50.8218), (6.00359, 50.8126), (5.99832, 50.8007),
                  (5.98395, 50.7922), (5.96876, 50.7946), (5.973, 50.7818),
                  (5.98065, 50.7734), (5.99057, 50.769), (5.99708, 50.7629),
                  (5.99491, 50.7499), (5.97476, 50.7475), (5.9022, 50.749),
                  (5.89132, 50.7512), (5.89129, 50.7512), (5.87988, 50.7535),
                  (5.79317, 50.7521), (5.78293, 50.7567), (5.76247, 50.771),
                  (5.75244, 50.7734), (5.74356, 50.7691), (5.73278, 50.7589),
                  (5.72785, 50.7542), (5.71741, 50.7528), (5.70656, 50.7542),
                  (5.68837, 50.7608), (5.6987, 50.7838), (5.70046, 50.7956),
                  (5.68485, 50.7985), (5.66325, 50.8051), (5.65743, 50.8076),
                  (5.64072, 50.815), (5.62449, 50.8303), (5.62232, 50.8527),
                  (5.69446, 50.9037), (5.70604, 50.9066), (5.71761, 50.9092),
                  (5.72237, 50.9117), (5.73529, 50.924), (5.75255, 50.9472),
                  (5.76402, 50.9594), (5.7543, 50.9631), (5.74469, 50.9632),
                  (5.72237, 50.9594), (5.76175, 50.9992), (5.77756, 51.0236),
                  (5.76402, 51.0352), (5.7664, 51.0484), (5.77146, 51.0581),
                  (5.77963, 51.0613), (5.7913, 51.055), (5.79885, 51.0615),
                  (5.80433, 51.0686), (5.81177, 51.0823), (5.80898, 51.0863),
                  (5.80743, 51.0894), (5.80495, 51.0966), (5.8159, 51.0959),
                  (5.82665, 51.0969), (5.83678, 51.0995), (5.84598, 51.1034),
                  (5.82324, 51.1187), (5.82644, 51.1302), (5.8405, 51.1389),
                  (5.83802, 51.1437), (5.82913, 51.1565), (5.81208, 51.1573),
                  (5.78138, 51.1524), (5.76805, 51.1595), (5.74717, 51.1776),
                  (5.73084, 51.1838), (5.71803, 51.1846), (5.67617, 51.1792),
                  (5.65901, 51.1791), (5.64816, 51.184), (5.63855, 51.1909),
                  (5.62501, 51.1969), (5.56837, 51.2077), (5.55141, 51.2168),
                  (5.54553, 51.2199), (5.54233, 51.2427), (5.5352, 51.262),
                  (5.5167, 51.2772), (5.49324, 51.2865), (5.47163, 51.2881),
                  (5.45189, 51.2821), (5.40993, 51.2635), (5.38906, 51.2587),
                  (5.27072, 51.2618), (5.23946, 51.2569), (5.23299, 51.2559),
                  (5.21542, 51.2587), (5.21491, 51.2943), (5.19734, 51.3083),
                  (5.17884, 51.3095), (5.14018, 51.3074), (5.12292, 51.3134),
                  (5.11806, 51.3199), (5.10783, 51.342), (5.10256, 51.3507),
                  (5.06814, 51.3745), (5.06174, 51.3843), (5.06525, 51.4059),
                  (5.07641, 51.4219), (5.07993, 51.4385), (5.06029, 51.462),
                  (5.03032, 51.4744), (5.02753, 51.4768), (5.01213, 51.4743),
                  (5.00613, 51.4683), (5.00272, 51.459), (4.9958, 51.4467),
                  (4.98019, 51.4305), (4.95714, 51.411), (4.93193, 51.3956),
                  (4.91033, 51.3919), (4.87167, 51.403), (4.85327, 51.4061),
                  (4.7833, 51.4076), (4.76212, 51.4134), (4.7678, 51.4254),
                  (4.77907, 51.4264), (4.82268, 51.4137), (4.81545, 51.4311),
                  (4.81989, 51.4462), (4.82609, 51.4606), (4.82392, 51.4756),
                  (4.81359, 51.4841), (4.79684, 51.491), (4.77865, 51.4954),
                  (4.76418, 51.4962), (4.73121, 51.4856), (4.65391, 51.4262),
                  (4.64357, 51.4214), (4.63014, 51.4182), (4.61463, 51.4176),
                  (4.5827, 51.4226), (4.55386, 51.4193), (4.54063, 51.4201),
                  (4.52151, 51.4286), (4.52337, 51.4384), (4.53185, 51.4509),
                  (4.53319, 51.4676), (4.52523, 51.4759), (4.51262, 51.4774),
                  (4.48306, 51.4743), (4.42942, 51.462), (4.37713, 51.4429),
                  (4.38922, 51.4346), (4.38715, 51.4275), (4.38064, 51.4197),
                  (4.37992, 51.4095), (4.38767, 51.4005), (4.4101, 51.3838),
                  (4.4162, 51.374), (4.41123, 51.3567), (4.39222, 51.3504),
                  (4.34561, 51.3523), (4.32628, 51.3564), (4.2901, 51.3688),
                  (4.28112, 51.3689), (4.26107, 51.3694), (4.25709, 51.3725),
                  (4.24903, 51.3842), (4.24635, 51.3964), (4.24684, 51.4067),
                  (4.24488, 51.4145), (4.23471, 51.419), (4.22299, 51.4095),
                  (4.20102, 51.4053), (4.11109, 51.407), (4.09034, 51.4113),
                  (4.07016, 51.419), (4.01515, 51.4489), (3.99879, 51.4531),
                  (3.95704, 51.4558), (3.94313, 51.4504), (3.91342, 51.4153),
                  (3.90211, 51.4049), (3.88673, 51.3998), (3.85076, 51.3974),
                  (3.8379, 51.3922), (3.82716, 51.3911), (3.81642, 51.3941),
                  (3.78907, 51.4122), (3.72877, 51.4308), (3.68971, 51.4543),
                  (3.674, 51.4554), (3.63258, 51.4457), (3.61004, 51.4451),
                  (3.5534, 51.4531), (3.53541, 51.4592), (3.52019, 51.4734),
                  (3.50685, 51.4893), (3.4948, 51.5009), (3.46192, 51.519),
                  (3.45102, 51.5297), (3.44703, 51.546), (3.45753, 51.5551),
                  (3.56039, 51.5946), (3.82887, 51.6127), (3.85108, 51.6108),
                  (3.86606, 51.6054), (3.88217, 51.5961), (3.89649, 51.5838),
                  (3.90577, 51.5692), (3.89527, 51.5666), (3.87827, 51.5594),
                  (3.87159, 51.5556), (3.87159, 51.5494), (3.9673, 51.5431),
                  (4.01588, 51.5308), (4.05714, 51.5084), (4.07032, 51.4927),
                  (4.09002, 51.4582), (4.10483, 51.4457), (4.12875, 51.4414),
                  (4.18084, 51.4459), (4.20045, 51.4395), (4.22023, 51.4435),
                  (4.25278, 51.4425), (4.26385, 51.4444), (4.28321, 51.4477),
                  (4.29672, 51.4705), (4.28858, 51.4921), (4.26775, 51.5083),
                  (4.23976, 51.5185), (4.23048, 51.5196), (4.19467, 51.5236),
                  (4.15333, 51.5351), (4.13795, 51.5359), (4.10629, 51.5335),
                  (4.09132, 51.5351), (4.06723, 51.544), (3.98813, 51.5903),
                  (4.04119, 51.606), (4.06772, 51.6107), (4.15724, 51.6079),
                  (4.18336, 51.6029), (4.20688, 51.5905), (4.20729, 51.5903),
                  (4.20265, 51.6091), (4.18995, 51.6167), (4.18613, 51.6168),
                  (4.14666, 51.6179), (4.136, 51.6204), (4.12599, 51.6247),
                  (4.11801, 51.6307), (4.11297, 51.6394), (4.10987, 51.6509),
                  (4.10963, 51.6623), (4.11264, 51.6708), (4.12566, 51.6796),
                  (4.14291, 51.6841), (4.17693, 51.6859), (4.16635, 51.6927),
                  (4.14112, 51.7039), (4.07154, 51.7172), (4.05714, 51.7303),
                  (4.05079, 51.7635), (4.03395, 51.7842), (4.00978, 51.7979),
                  (3.98146, 51.81), (3.96258, 51.8012), (3.93719, 51.7963),
                  (3.91139, 51.7964), (3.89186, 51.793), (3.88819, 51.7889),
                  (3.88111, 51.7881), (3.87159, 51.7883), (3.86232, 51.8161),
                  (3.89137, 51.8283), (3.95411, 51.8402), (3.96266, 51.8474),
                  (3.98219, 51.8483), (4.01564, 51.8436), (4.04347, 51.8342),
                  (4.04762, 51.8337), (4.05502, 51.8342), (4.06544, 51.8371),
                  (4.07765, 51.8436), (4.07008, 51.8527), (4.04461, 51.8745),
                  (4.03785, 51.8779), (4.03207, 51.882), (4.0298, 51.8883),
                  (4.03199, 51.8961), (4.03663, 51.9016), (4.04127, 51.9055),
                  (4.04347, 51.9087), (4.04021, 51.9241), (4.02117, 51.9633),
                  (4.01002, 51.9801), (4.01564, 51.9877), (4.02247, 51.9944),
                  (4.06902, 51.9879), (4.10768, 51.9919), (4.14186, 52.0056),
                  (4.28468, 52.1129), (4.40691, 52.2235), (4.50815, 52.3364),
                  (4.56861, 52.4453), (4.57732, 52.4736), (4.57732, 52.4809),
                  (4.59693, 52.5066), (4.63933, 52.7007), (4.65707, 52.7502),
                  (4.65984, 52.7653), (4.66944, 52.7966), (4.71168, 52.8631),
                  (4.72136, 52.8959), (4.72242, 52.9145), (4.72641, 52.9383),
                  (4.7339, 52.9589), (4.74545, 52.9676), (4.80698, 52.9618),
                  (4.81691, 52.9676), (4.82439, 52.9602), (4.80942, 52.9296),
                  (4.83277, 52.9113), (4.87379, 52.904), (4.9131, 52.9056),
                  (4.9358, 52.9134), (4.97828, 52.9357), (4.99903, 52.9403),
                  (5.03891, 52.9435), (5.07814, 52.954), (5.27947, 53.0629),
                  (5.2942, 53.0734), (5.31275, 53.0828), (5.3589, 53.0893),
                  (5.37924, 53.0974), (5.39975, 53.1221), (5.42709, 53.1903),
                  (5.44744, 53.2209), (5.4826, 53.2456), (5.50424, 53.257),
                  (5.54103, 53.2666), (5.55787, 53.278), (5.5735, 53.2917),
                  (5.59156, 53.3028), (5.61183, 53.3071), (5.65968, 53.312),
                  (5.69459, 53.3301), (5.85475, 53.3688), (5.8908, 53.3843),
                  (5.91375, 53.3854), (5.9808, 53.4061), (6.07732, 53.4089),
                  (6.18605, 53.411), (6.27394, 53.4127), (6.28435, 53.4105),
                  (6.30193, 53.4011), (6.31153, 53.399), (6.32008, 53.4007),
                  (6.34555, 53.4127), (6.4944, 53.4387), (6.73024, 53.4606),
                  (6.82911, 53.4506), (6.84978, 53.4449), (6.86687, 53.4343)])
Exemple #11
0
def create_polygon(vertex_count, radius, center=(0, 0), angle=0):
    poly = Polygon.regular(vertex_count, radius, center, angle)
    points = to_points(poly)
    return points
Exemple #12
0
def is_convex_quadrangle(box):
    polygon = Polygon(box)
    return polygon.is_convex
Exemple #13
0
def leiwand(args):

    poly = {}
    filename = "data.txt"
    output = "graph"
    for arg in args:
        if "in=" in arg:
            filename = arg.split("=")[1]
        if "out=" in arg:
            output = arg.split("=")[1]
        if "coord" in arg:
            tmp = arg.split("_")[1].split("=")
            name = tmp[0]
            coord = tmp[1].split(",")
            coord = [float(coord[0]), float(coord[1])]
            poly[name] = coord
        elif "=" in arg:
            tmp = arg.split("=")
            variables[tmp[0]] = tmp[1]

    if "bendall" in variables:
        for x in ["00", "11", "22", "01", "10", "02", "20", "21", "12"]:
            variables["bend" + x] = variables["bendall"]

    external_vertices = None
    if variables['vertices'] is not None:
        external_vertices = variables["vertices"].split(' ')
        # reverse order (drawing is counter-clockwise)
        external_vertices = list(reversed(external_vertices))
        print("got vertices: ", external_vertices)

    whitespace = None
    if variables["whitespace"] is not None:
        whitespace = variables["whitespace"]

    with open(output + ".tex", "w") as outf:
        data = []
        if "mathematica" in data:
            lines = data["mathematica"].split("{")
            for line in lines:
                if "}" in line:
                    tmp = line.split("}")
                    data.append(
                        (float(tmp[0]), str(tmp[1]).strip(), int(tmp[2]),
                         str(tmp[3]).strip(), int(tmp[4].strip("}"))))
        else:
            with open(filename, "r") as f:
                for line in f:
                    if line == "\n":
                        print("caught blanc line")
                        continue
                    line = line.strip()
                    line = line.strip(",")  # remove trailing comma
                    tmp = line.split(",")
                    data.append([
                        float(tmp[0]),
                        str(tmp[1]).strip(),
                        int(tmp[2]),
                        str(tmp[3]).strip(),
                        int(tmp[4])
                    ])
        optionmap = {
            (0, 0): "color=zerocol, bend right=" + variables["bend00"],
            (1, 1): "color=onecol, bend right=" + variables["bend11"],
            (2, 2): "color=twocol, bend right=" + variables["bend22"],
            (0, 1):
            "bicolor={zerocol}{onecol}, bend left=" + variables["bend01"],
            (1, 0):
            "bicolor={onecol}{zerocol}, bend right=" + variables["bend10"],
            (0, 2):
            "bicolor={zerocol}{twocol}, bend left=" + variables["bend20"],
            (2, 0):
            "bicolor={green}{zerocol}, bend right=" + variables["bend02"],
            (1, 2):
            "bicolor={onecol}{twocol}, bend left=" + variables["bend12"],
            (2, 1):
            "bicolor={twocol}{onecol}, bend right=" + variables["bend21"],
        }

        if whitespace is not None:
            print("\documentclass[border={}]{}".format(whitespace,
                                                       r"{standalone}"),
                  file=outf)
        else:
            print(r"\documentclass{standalone}", file=outf)
        print(r"""
        
        \usepackage{tikz}
        \usepackage{verbatim}
        
        \usetikzlibrary{decorations.markings}
        
        \begin{document}
        \pagestyle{empty}
    """,
              file=outf)
        colors = r"\definecolor{vertexcol}" + variables["vertexcolor"]
        colors += r"\definecolor{onecol}" + variables["color0"]
        colors += r"\definecolor{twocol}" + variables["color1"]
        colors += r"\definecolor{zerocol}" + variables["color2"]
        colors += r"\definecolor{fontcolor}" + variables["fontcolor"]
        print(colors, file=outf)
        print(r"""
        \newlength\mylen
        % check https://tex.stackexchange.com/questions/270001/tikz-coloring-edge-segments-with-different-colors
        \tikzset{
        bicolor/.style n args={2}{
          decoration={
            markings,
            mark=at position 0.5 with {
              \node[draw=none,inner sep=0pt,fill=none,text width=0pt,minimum size=0pt] {\global\setlength\mylen{\pgfdecoratedpathlength}};
            },
          },
          draw=#1,
          dash pattern=on 0.5\mylen off 1.0\mylen,
          preaction={decorate},
          postaction={
            draw=#2,
            dash pattern=on 0.5\mylen off 0.5\mylen,dash phase=0.5\mylen
          },
          }
        }
        
        \begin{tikzpicture}
          \tikzstyle{vertex}=[circle, draw=black, ultra thick ,fill=vertexcol!80,minimum size=15pt]\textbf{}
        """,
              file=outf)

        vertices = []
        weights = []
        for d in data:
            weights.append(abs(d[0]))
            vertices.append(d[1])
            vertices.append(d[3])
        vertices = list(set(vertices))
        max_weight = max(weights)

        # check if vertices where specified manually
        if external_vertices is not None:
            print("replacing: ", vertices)
            print("with external vertices: ", external_vertices)
            vertices = external_vertices
        else:
            #sort vertices alphabetically
            vertices = list(reversed(sorted(vertices)))

        if len(poly) < len(vertices):
            poly = Polygon.regular(len(vertices),
                                   radius=5,
                                   angle=float(variables["angle"]))
        else:
            # sort alphabetically
            poly = reversed(
                list(dict(sorted(poly.items(), key=lambda x: x[0])).values()))
        for i, coord in enumerate(poly):
            print(r"\node[vertex] ({name}) at ({x},{y}) {xname};".format(
                name=vertices[i],
                xname=r"{\color{fontcolor}" + vertices[i] + "}",
                x=coord[0],
                y=coord[1]),
                  file=outf)

        edge_string = r"\path ({v1}) edge[{options}, opacity={opacity}] ({v2});"
        for d in data:
            assert (len(d) == 5)
            weight = d[0]
            v1 = d[1]
            t1 = d[2]
            v2 = d[3]
            t2 = d[4]
            opacity = max(0.3, abs(weight) / max_weight)
            print(edge_string.format(
                v1=v1,
                v2=v2,
                options="line width={lw},".format(lw=variables["line_width"]) +
                optionmap[(t1, t2)],
                opacity=opacity),
                  file=outf)

        print(r"""
        \end{tikzpicture}
        
        \end{document}
        """,
              file=outf)

    print("created {}.tex".format(output))
    print(
        "trying to compile with pdflatex ... might be caught in endless loop")

    import subprocess
    from shutil import which

    system_has_pdflatex = which("pdflatex") is not None
    if not system_has_pdflatex:
        raise Exception(
            "You need pdflatex in order to export circuits to pdfs")

    with open(output + ".log", "w") as file:
        subprocess.call(["pdflatex", output + ".tex"], stdout=file)

    print("created {}.pdf".format(output))
Exemple #14
0
# need to be in the etc conda env
from planar import Polygon
import numpy as np 
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import matplotlib

fig = plt.figure()
ax = Axes3D(fig)

h1 = np.asarray(Polygon.regular(6, radius=5.5, angle=30))
h1 = np.hstack([h1, np.zeros(6).reshape([6,1])])
h2 = h1 
h2[:,2] =- 3

v1 = [list(zip(h1.tolist()))]
v2 = [list(zip(h2.tolist()))]
ax.add_collection3d(Poly3DCollection(v1))
ax.add_collection3d(Poly3DCollection(v2))

plt.show()
Exemple #15
0
def poly_from_dict(dikt):
    return Polygon.from_points([vec2_from_dict(v) for v in dikt['points']])
Exemple #16
0
from planar import Polygon, Vec2

ROBOT_MAX_ACC = 1.6 # m/s^2
ROBOT_MAX_V = 0.6 # m/s
ROBOT_RADIUS = 0.2 # m

PLAYGROUND_BORDER = Polygon([Vec2(0,0),Vec2(3,0),Vec2(3,2),Vec2(0,2)])

PLAYGROUND_WIDTH = 3
PLAYGROUND_HEIGHT = 2

DELTA_T = 0.1 # s

ROBOT_POLYGON = Polygon.regular(32,radius = ROBOT_RADIUS)

unit_circle_approx = Polygon.regular(24,radius = 1)
Exemple #17
0
def create_star(peak_count, radius1, radius2, center=(0, 0), angle=0):
    star = Polygon.star(peak_count, radius1, radius2, center, angle)
    points = to_points(star)
    return points