How do I calculate the normal vector of a line segment? [closed]
If we define dx = x2 – x1 and dy = y2 – y1, then the normals are (-dy, dx) and (dy, -dx). Note that no division is required, and so you’re not risking dividing by zero.
If we define dx = x2 – x1 and dy = y2 – y1, then the normals are (-dy, dx) and (dy, -dx). Note that no division is required, and so you’re not risking dividing by zero.
Taking E is the starting point of the ray, L is the end point of the ray, C is the center of sphere you’re testing against r is the radius of that sphere Compute: d = L – E ( Direction vector of ray, from start to end ) f = E – C ( … Read more
Here is how I would do it: bool intersects(CircleType circle, RectType rect) { circleDistance.x = abs(circle.x – rect.x); circleDistance.y = abs(circle.y – rect.y); if (circleDistance.x > (rect.width/2 + circle.r)) { return false; } if (circleDistance.y > (rect.height/2 + circle.r)) { return false; } if (circleDistance.x <= (rect.width/2)) { return true; } if (circleDistance.y <= (rect.height/2)) … Read more
From the documentation for scatter: Optional kwargs control the Collection properties; in particular: edgecolors: The string ‘none’ to plot faces with no outlines facecolors: The string ‘none’ to plot unfilled outlines Try the following: import matplotlib.pyplot as plt import numpy as np x = np.random.randn(60) y = np.random.randn(60) plt.scatter(x, y, s=80, facecolors=”none”, edgecolors=”r”) plt.show() Note: … Read more
I thought I might briefly mention my own polygon clipping and offsetting library – Clipper. While Clipper is primarily designed for polygon clipping operations, it does polygon offsetting too. The library is open source freeware written in Delphi, C++ and C#. It has a very unencumbered Boost license allowing it to be used in both … Read more
Simply put this block of xml in your activity layout file: <RelativeLayout android:id=”@+id/loadingPanel” android:layout_width=”match_parent” android:layout_height=”match_parent” android:gravity=”center” > <ProgressBar android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:indeterminate=”true” /> </RelativeLayout> And when you finish loading, call this one line: findViewById(R.id.loadingPanel).setVisibility(View.GONE); The result (and it spins too):
How to generate a random point within a circle of radius R: r = R * sqrt(random()) theta = random() * 2 * PI (Assuming random() gives a value between 0 and 1 uniformly) If you want to convert this to Cartesian coordinates, you can do x = centerX + r * cos(theta) y = … Read more
In general, the simplest (and quite optimal) algorithm is checking on which side of the half-plane created by the edges the point is. Here’s some high quality info in this topic on GameDev, including performance issues. And here’s some code to get you started: float sign (fPoint p1, fPoint p2, fPoint p3) { return (p1.x … Read more
Some of the suggested methods will fail in the case of a non-convex polygon, such as a crescent. Here’s a simple one that will work with non-convex polygons (it’ll even work with a self-intersecting polygon like a figure-eight, telling you whether it’s mostly clockwise). Sum over the edges, (x2 − x1)(y2 + y1). If the … Read more
In general, x and y must satisfy (x – center_x)² + (y – center_y)² < radius². Please note that points that satisfy the above equation with < replaced by == are considered the points on the circle, and the points that satisfy the above equation with < replaced by > are considered the outside the … Read more