In my game I draw the line using two points. I want to calculate the points between the line. Please give any formula for finding points between the two points.
If your two points are A and B then
r(t) = A + t(B - A) , where t is greater than or equal to 0 and less than or equal to 1
is the equation of the line joining A to B, and consequently allows you to find any point lying on the line between them (by using an appropriate value for t).
Does this help??
Related
I have an image like this one
with 3 distinct regions. Using a breath first 4 neighbor queue, I have implemented a basic flood fill that distinguishes between the 3.
Now I need to find the center of mass of these regions with each pixel weighing one unit of weight.
Whats the best way of going about that?
The simplest way is to keep three arrays, sumx, sumy and count, each with one entry per label (3 in your case), and all initialized to 0. Then run through the image once, and for each labeled pixel add the x coordinate to the corresponding bin in sumx, the y coordinate to the corresponding bin in sumy, and 1 to the corresponding bin in count.
At the end, for each label l you can compute sumx[l]/count[l] and sumy[l]/count[l]. These are the unweighted centers of gravity (centroids).
Can someone please explain to me what a straight-line distance heuristic would look like while solving the n-puzzle? How would you apply the straight line distance, say for a 8x8 puzzle? Here is an example puzzle:
7 3 4
5 _ 6
8 2 1
Let's recall basic geometry, it is well known that the shortest path between two points is a straight line.
So considering a 8-puzzle, the straight line distance between two tiles is the number of tiles to get from tile A to tile B whether is diagonal, horizontal or vertical line.
Considering the example in your question, let's call d(a,b) the straight line distance between tile a and b:
d(1,_) = 1
d(1,2) = 1
d(1,3) = 2 = d(1,6) + d(6,3) = d(1,_ ) + d(_,3)
d(1,4) = 2
and so on.
We can now generalize that definition to the n-puzzle. Keep in mind that 3 steps are allowed diagonal, horizontal, vertical. In this case the heuristic is usually optimal.
Note: Remember the straight line definition between cities.
There is a sloping LineSeries with two points showing a straight line. How can I calculate the Y value so the line continues infinitely in the same direction?
This line is like a guide-line that should follow along when values are added to another Series in the same chart. But must never change angle.
I'm using Delphi and Lazarus.
Suppose that the line passes through (x0,y0) and (x1,y1). The slope of the line k is given by:
k = (y1-y0) / (x1-x0)
So the line can be expressed as
y(x) = y0 + k(x-x0)
So you need to add points to the series whose x values are the minimum and maximum x values displayed on the chart. And whose y values are calculated as above.
This assumes that the line is not vertical, that is that x0 does not equal x1. If the line is vertical then the solution is trivial. Place points at the y values of the minimum and maximum values of the chart.
i need to find out contact angle between 2 edges in an image using open cv and python so can anybody suggest me how to find it? if not code please let me know algorithm for the same.
Simplify edge A and B into a line equation (using only the few last pixels)
Get the line equations of the two lines (form y = mx + b)
Get the angle orientations of the two lines θ=atan|1/m|
Subtract the two angles from each other
Make sure to do the special case of infinite slope, and also do some simple math to get Final_Angle = (0;pi)
I'm currently finishing my evaluation-tool for interest point detectors. In the last steps I found a confusing error.
Mat findHomography(InputArray srcPoints, InputArray dstPoints, int method=0, double ransacReprojThreshold=3, OutputArray mask=noArray() )
The srcPoints and dstPoints are vector<Points2f> which stores the corresponding points of the matched keypoints. So far nothing special - It's like in the tutorials.
But when I use RANSAC and have a vector<Points2f> in range [0, ... , 4], I get an assertion error than the counter should be greater or equals four.
Question 1: Does the algorithm needs at least four points to describe what belongs to the current model or not and to create the consensus?
Question 2: Is there any documentation about this? (I took a look at the doc and the tutorials.)
Please note that I already have seen this question. But there is no satisfying answer for the behaviour of RANSAC. Or should I accept that this methods needs at least four points to find the homography?
Thanks for your help.
A homography cannot be computed with less than 4 pairs of points. That is because with only 3 points there is a perspective ambiguity. Picture a triangle
a
b c
in image 1. In image 2 the points have been transformed to look like this
a
b c
The distance between b and c has been cut in half. Unfortunately you don't know if that is because point c got closer to your or farther from you. With a 4th point the difference becomes clear.
a d
b c
Here is a square in image 1
d
a
b c
here d and c rotated towards you
a
d
b c
and here they rotated away from you.
I don't see this requirement in the openCV documentation but if you find any resources on homography calculation you won't have to read very far before you find this requirement and a more rigorous proof of 4 points being sufficient.
RANSAC is used to select 4 pairs of matching points in a greater set or correspondences (i.e. when srcPoints.size() >= 4). That's why you get an error if srcPoints.size() <=4.
You need at least 4 correspondences simply because a Homography matrix H has 8 degrees of freedom, hence 8 linear equations are required to find a solution. Since each pairs of points generates two linear equations (using x and y coordinates) you'll need a total of at least 4 correspondences.