This is a programming homework assignment, of which I have no qualms about doing it myself however I'm quite stuck on the geometry of it. I need to be able to determine the exact point of intersection given the center and radius of a circle and two end points of a vertical line segment, and since geometry isn't my forte I was hoping for some help (even pointers in the right direction would be appreciated!)
This probably isn't the best place to ask a question like this but I'm not really sure where else to look for help, my apologies if it's against the rules or something.
edit:
My apologies, what I am really having trouble with is determining what the points of intersection are (and if there is one intersection or two.) I've tried each solution given and they work great for determining if there is an intersection or not but my problem still persists as I mis-worded my question. If anyone can help with that it'd be much appreciated!
Try http://mathworld.wolfram.com/Circle-LineIntersection.html, this covers the geometry aspect of your problem quite well.
If C=(x0,y0) is the center, r the radius, and k the abscissa of the line, you have
y = y0 +/- sqrt(r^2-(k-x0)^2), but no intersection if r < abs(k-x0)
using the centre [x,y] of the circle, find the distance of this particular line from the centre.refer
now if this distance is > radius of the circle => the line won't intersect. otherwise, it will.
Related
How can I divide a convex polygon into quadrilaterals considering the hatched polygons (holes) already in place. Any suggestions will be greatly helpful.
What am I actually trying to do is to find quadrilateral strips as two of them are shown below. I thought may be dividing the whole polygon into quadrilaterals would help achieving this.
For example the light source is coming from 1,3,-5 and object is at 4,-2,-1.
Algebraic formula is going to give the answer as 3. [1,3-5].[4,-2,-1]
= 1*4 + 3*-2 + -5*-1 = 3
But what does this 3 means? How do I know if my object is shaded with this number 3? Or is there more to it? I did look around and unable to find anything conclusive. Would be great if someone could give some insight. Thank you.
Judging from answers, pondering if I am understanding my question wrong. I was trying to get my head around the following question:
For a point on a convex surface, with the normal n=(n1,n2,n3)and light
direction l = (l1,l2,l3), determine if the point can be seen by light
source.
Using a dot product between two points makes no sense. Essentially, a dot product gives a measure of how similar two vectors are. When applied to points, the value will be related to the similarity of the direction to the points from the origin, as well as their distance from it. That metric doesn't make much sense, as you found out with that '3'.
To determine the amount of illumination, you want to be using a dot product between the normalized vector of the direction from the surface to the light and the surface normal. The result will be a value from -1 to 1, which you can interpret as an illumination factor for simple gouraud shading. In pseudocode:
illumination = max(0, dot(normalize(lightPosition - positionOnSurface), surfaceNormal))
Determining if a light hits an object is an entirely different problem called occlusion, and not really something you express in as mathematical formula. It's about testing what objects are in the path from the light to your target object.
The dot product can tell you on what side of a line a point is. The triangle is formed by three lines. If you are on the same side of all three lines then you are inside the triangle. You can use three dot products to test for each of the three sides. See slide 23 on this link http://comp575.web.unc.edu/files/2010/09/06raytracing1.pdf.
I am not good with math,and i just need someone to point me in the right direction.
Latitude Longitude
N 36° 13.488' W 095° 54.295'
N 36° 13.488' W 095° 53.805'
Assume that all three are located on a flat plane, at the same elevation.
Assume that the curvature of the earth is not a factor.
Assume that there are exactly 69.1691 miles per degree of latitude.
Assume that there are 55.9588 miles per degree of longitude (Tulsa area only)..
I am trying to figure out what the last points coordinate is.
Can anyone help. I just dont know where to begin
There are numerous ways to find the third point. The angles in an equilateral triangle are all 60 degrees. The third point lies on the bisector of the line connecting the two points you have. Expressing the points and lines using vectors, rather than coordinates, helps.
But the truth is, if you do not have enough mathematical knowledge for this kind of problem, you probably ought not to be tackling it as a programming problem. How can you know you've done it right?
I have a rotate rectangle and I know the size of the diagonal. I also know the angle used to rotate the rectangle.
How can I calculate the width and height of the rectangle?
For a sketch of the problem, see:
1) create a new line starting at one of the end-points of the diagonal and travelling at the rotation angle.
2) project the other diagonal terminus onto this line. You now know one side of the rectangle.
3) Copy the segment to the other side of the diagonal and connect the endpoints to complete the rectangle.
The only 'tricky' code here is the projection. This webpage has some example code for Point-Line distance/projection: http://softsurfer.com/Archive/algorithm_0102/algorithm_0102.htm
Thanks David Rutten,
I got it working. Your site about the projection was to much for my math knowledge, but with some google i find a nice point to line intersection function which helped me to calc the length (distance) of one of the sides.
Unfortunately I'm too "new" here to award you with credits or reply on your anwser.
#Eric bainville: I knew the distance because i had point1 and point2 (upper left and bottom right) coordinates. With those coordinates it is possible. I didnt mention this, but luckily David guessed right that I knew them.
Thanks again!
I know this is more high school math(wow been a long time since I was there) but I am trying to solve this programatically so I am reaching out to the collective knowledge of stackoverflow
Given this layout:
Midpoint is my reference point and in an array I have the vector points of all other points (P)
I can get to this state with code of having the light blue area by breaking it into four quadrants and doing a lame bubble sort to find largest(y) or lowest(x) value in each quadrant.
I need to find only the quadrants that outer border fully hits red no white space. For example the lower left and the up right dont have any white space hitting the light blue rectangle.
I am sure my terminology is all off here and im not looking for any specific code but if someone could point me to a more optimized solution for this problem or the next step in what I already have.
Thank you
I might do some BFI solution first, then perhaps look to generalize it or at least reduce it to a table-drive loop.
So, if it's exactly these shapes, and not a general solution, I think you should proceed sort of like this:
Derive the coordinates of the blue rectangle. I suspect one thing that's confusing you is that you have each individual x and y for the blue rect but you can't easily loop through them.
Derive the coordinates of the midpoint of each rectangle edge. You are going to need this because you care about quadrants. It will be trivial to do this once you have done 1.
Write different code for each 1/2 rectangle edge. There is no doubt a more clever way but this will get working code.
Make it more elegant now if you care. I betg you can reduce the rules to an 8-row
table full of things like 1, -1, or something like that.
First, you can't define red area by a single vector, since it's disjoint. You need the same number of vectors as the number of distant red regions.
Second, do we assume that different red figures neither intersect nor share a border? In the next clause I do.
Third, under assumption in point 2, the quadrant will have all red outer side iff there exists a contiguous red figure that intersects both its axes (i.e. rays). To determine this for all quadrants, you should only traverse all (P) points in the order they're given. This takes linear time and solves the problem.