polygon

ggplot: How to produce a gradient fill within a geom_polygon

泄露秘密 提交于 2019-11-28 03:30:22
问题 This should be fairly easy but I can't find my way thru. tri_fill <- structure( list(x= c(0.75, 0.75, 2.25, 3.25), y = c(40, 43, 43, 40)), .Names = c("x", "y"), row.names = c(NA, -4L), class = "data.frame",Integrated=NA, Related=NA) # install.packages("ggplot2", dependencies = TRUE) require(ggplot2) ggplot(data=tri_fill,aes(x=x, y=y))+ geom_polygon() + scale_fill_gradient(limits=c(1, 4), low = "lightgrey", high = "red") What I want is a gradient along the x-axis, but with the above I only get

How to create a Polygon given its Point vertices?

陌路散爱 提交于 2019-11-28 02:37:56
问题 I want to create a polygon from shapely points. from shapely import geometry p1 = geometry.Point(0,0) p2 = geometry.Point(1,0) p3 = geometry.Point(1,1) p4 = geometry.Point(0,1) pointList = [p1, p2, p3, p4, p1] poly = geometry.Polygon(pointList) gives me an type error TypeError: object of type 'Point' has no len() How to create a Polygon from shapely Point objects? 回答1: If you specifically want to construct your Polygon from the shapely geometry Points, then call their x, y properties in a

Mathplotlib draw triangle with gradient fill

…衆ロ難τιáo~ 提交于 2019-11-28 02:23:18
I have to draw a triangle in Python using mathplotlib. This is how it should eventually look like: My objective is, once drawn the triangle, to plot some points on it. At the moment I can draw the triangle just fine: import matplotlib.pyplot as plt from matplotlib.patches import Polygon fig = plt.figure() ax = fig.add_subplot(111, aspect='equal') ax.add_patch(Polygon([[0,0],[0,1],[1,0]], closed=True,fill=True)) ax.set_xlim((0,1)) ax.set_ylim((0,1)) plt.show() But I can only fill it with a solid color. How do I add a gradient like shown in the picture? Can some one help me? There is an example

Finder what point is to the left of a line/point after spinning it

徘徊边缘 提交于 2019-11-28 02:20:11
I am currently trying to write a shader in unity that draws a triangular pattern around countries in a risk-styled game if both countries are not owned by the same player (visual aid to see your borders). Right now, I'm having an issue with making the shader set the countries properly. It always sets country 0 to the left, and country 1 to the right - country 0 and 1 are set programically. The line, a border, can be between 0 and 359 degrees. How I find the countries 0 and 1 is I draw 3 points to the left and right of the midpoint of the line, one .01f, one .1f and one 1f away from the

How can I create an internal spiral for a polygon?

核能气质少年 提交于 2019-11-28 01:27:17
For any shape how can I create a spiral inside it of a similar shape. This would be a similar idea to bounding (using Minkowski sum). Rather than creating the same shape inside the shape though it would be a spiral of same shape. I found this - http://www.cis.upenn.edu/~cis110/13su/lectures/Spiral.java It creates a spiral based on the parameters passed so it can be for any regular shape. I want the above for all shapes i.e. irregular polygons too. I am not hugely familiar with geometric terminology but I have looked up Involutes and an Internal Spiral Search Algorithm too but haven't been

Calculate the area of a polygon with latitude and longitude

不羁的心 提交于 2019-11-27 22:47:59
问题 I have this code, written using this: source1 and this: source 2 public static double CalculatePolygonArea(IList<GpsLocation> coordinates) { double area = 0; if (coordinates.Count > 2) { for (var i = 0; i < coordinates.Count-1; i++) { GpsLocation p1, p2; p1 = coordinates[i]; p2 = coordinates[i + 1]; area += ToRad(p2.Longitude - p1.Longitude) * (2 + Math.Sin(ToRad(p1.Latitude)) + Math.Sin(ToRad(p2.Latitude))); area = area * R * R / 2; } } return Math.Abs(area); } Here is my test code: [Fact]

Placing a MapLabel on top of a Polygon in Google Maps V3

↘锁芯ラ 提交于 2019-11-27 21:18:58
问题 I'm trying to place a MapLabel on top of a Polygon in Google Maps V3. I've tried to set the MapLabel zIndex to 2 and the Polygon zIndex to 1 without any luck. Isn't this possible since the Polygon doesn't really follow zIndex? I've created a jsFiddle for you guys to check out: http://jsfiddle.net/7wLWe/1/ Solution: In maplabel.js change: mapPane.appendChild(canvas); to: floatPane.appendChild(canvas); The reason is because floatPane is above all map layers (pane 6) http://code.google.com/apis

How do you draw transparent polygons with Python?

房东的猫 提交于 2019-11-27 21:10:46
问题 I'm using PIL (Python Imaging Library). I'd like to draw transparent polygons. It seems that specifying a fill color that includes alpha level does not work. Are their workarounds? If it can't be done using PIL I'm willing to use something else. If there is more than one solution, then performance should be factored in. The drawing needs to be as fast as possible. 回答1: This is for Pillow, a more maintained fork of PIL. http://pillow.readthedocs.org/ If you want to draw polygons that are

How can you find the centroid of a concave irregular polygon in JavaScript?

早过忘川 提交于 2019-11-27 21:01:23
问题 How can you find the centroid of a concave irregular polygon given its vertices in JavaScript? I want to pass a set of x,y points to a JavaScript function and be given an x,y point. var my_points = [{x:3,y:1},{x:5,y:8},{x:2,y:9}]; function get_polygon_centroid(points){ // answer } var my_centroid = get_polygon_centroid(my_points); The my_points variable is only supposed to represent the format of the points to be given, not to represent the specific count of points to be given . The centroid

Circle and Polygon Collision with Libgdx

荒凉一梦 提交于 2019-11-27 20:52:50
Is there a way in Libgdx to verify a collision between a Polygon and a Circle? I saw the Intersector class but only found collision test for Circle and Rectangle. What about any other Polygon? If I need to do it manually, what's the best way to do that using Libgdx? So, I managed to create a collision test method between a Circle and a Polygon. At least, it works for me. Here's the code: public boolean overlaps(Polygon polygon, Circle circle) { float []vertices=polygon.getTransformedVertices(); Vector2 center=new Vector2(circle.x, circle.y); float squareRadius=circle.radius*circle.radius; for