How to find distance to each point inside rectangle? [closed] - math

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
For a given Xp,Yp and angle a inside a rectangle with (width = Xm, height = Ym) i need to find all distances d_angle (with angle between 0 and 359). I found a solution but it is too complicated. Maybe there is a simpler algorithm to find it in python or c++!

To check whether point P lies inside rectangle R:
if (P.X <= R.Right) and (P.X >= R.Left) and (P.Y <= R.Top) and (P.Y >= R.Bottom)
and note that math libraries of many programming languages contain function like PtInRect

You can find the azimuths of the four corners from the given point Xp, Yp, let a, b, c, d. These define four angular sectors that "see" the four sides. (To handle angle wraparound, consider the sectors [a, b), [b, c), [c, d) and [d-2π, a)U[d, a+2π)).
Now the distance to the right vertical side X=Xm is (Xm - Xp)/cos Θ. There are similar formulas for the other sides.

Related

Calculate Camera tilt angle [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
I have a camera I'd like to mount on a tripod. I know the FOV dimensions of the camera (22.5 deg V 31 deg H). I'd like to know at what height and what tilt angle to place the camera to be able to capture the two points of interest on the ground. Please see the figure below.
I have attempted a solution using basic trig but am not sure it is correct. Please help!
Your calculations are correct in my view.
If you have to include both the red points, you need to place your camera at an angle such that it encloses both the red points.
So, tan θ = d/hc
=> θ = tan -1 d/hc.
But, as you need to enclose both the points, your angle should be slightly greater than θ ( my suggestion --- some θ+ε, where 0.25 < ε < 1 ) to perfectly capture those 2 red dots.

Some math abaut circle need mathematical formula [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
I have no much time to research net, so can somebody derive the formula for calculating the point belonging to the circle?
as u can see we have point 5,-5 and center, and radius and angle. Thanks for advance, i know that isnt programming problem, but I need this to my project. OFC I see thats point 1,-1. but my pc probably will not ;/
For points inside the circle with radius R and center X,Y:
point (x,y) is inside the circle if:
(X-x)^2+(Y-y)^2 < R^2
Is that what you're after? No.
So what you need is a translate - rotate - translate.
So X,Y is the centre, x,y is the point and angle is the angle in degrees
# Translate
x = x-X ; y = y-Y
# Rotate
rad = angle*M_PI/180
xr = x*cos(rad) + y*sin(rad)
yr = -x*sin(rad) + y*cos(rad)
x = xr+X ; y = yr +Y
So if you only want 90 degrees, replace cos(rad) with 0 and sin(rad) with 1.

Determining Vector points on a circle [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
This question does not appear to be about programming within the scope defined in the help center.
Improve this question
I have a problem it is like trig and pre calc. We are given vector points for OA which is (6 0) and vector OB (-6 0) and OC (5 root11) and they are all points on a circle with a radius of 6. How exactly do you determine or show that these points lie on the circle?
For any three points which are not mutually co-linear, there is a point equidistant from each member of the set. Finding this point given three arbitrary points (and not given the radius) is a much more informative project if you're learning trigonometry.
In your example, the solution is simple: x2 + y2 = r2. Each of the points you provided have values such that the sum of their squares equals 36, as expected for a circle of radius 6. Your problem is especially easy because the circle in question is already centered on the origin.

Trajectory equation for object fired horizontally from a given height [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Does anyone know the equation to get the current x position and the current y position of a projectile with gravity and mass figured in? The object is fired horizontally from a given height h, with initial velocity v.
The trajectory will be a parabola. If you're fire the projectile horizontally (i.e. in positive x direction) at height y0, then you're entering the parabola at its vertex, for which I'll use coordinates (x0, y0). Ignoring friction, the horizontal component of your velocity will always equal the initial velocity, whereas the vertical velocity will increrase linearily with time. Intergrating that gives you the position for a given time t as:
x = x0 + vt
y = y0 − gt2/2
In the second equation, g denotes the gravitational acceleration of 9.81­ m/s2. Unless you consider friction, the mass of the object has no impact at all, as the higher gravitational force is compensated by the greater inertia. The equations obviously assume that positive y is up, and the gravity pulls down.

When drawing a square inside a circle, can you assume the width of the square is 4/3 of the circle radius? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I want to draw a square inside a circle. My circle has a radius of between 0.5 and 3.
is it safe to assume my square will always be 0.66 * 2 * radius wide/high?
I am making a function to calculate if a certain point is within the circle. I already made a square to get my points out of the database.
I want to make the square within the circle to quickly determine if a point is definately within my circle
The length of the diagonal of the square corresponds to two times the radius of the circle, i.e.
d = 2 * r
At the same time it is
d = sqrt(2) * a
where a is the length of one side of your square.
Thus
a = r * 2 / sqrt(2) = r * sqrt(2)
which is approximately
a = r * 1.41421
A square that fits exactly in a circle should have a side length of sqrt(2) * radius.
This depends on what your definition of exactly is.
If you're using integer math, of course not because you can't represent it that course.
If you're using floating point arithmetic, then you can't because you could have rounding errors.
If you're using floating point arithmetic with a sufficiently course episilon, then assuming you've done your math right, yes you can make that assumption.
If you're using a decimal system that isn't floating point, then again assuming you've done your math right, yes you can make that assumption.
But regardless, if you want to determine if a point is within your circle, just use the Pythagorean theorem to get your distance to the center and compare the distance. You don't even have to use expensive square roots if you instead square the radius.
boolean isInCircle(Circle c, Point p) {
double dx = c.center.x - p.x;
double dy = c.center.y - p.y;
double r2 = c.radius * c.radius;
return dx*dx + dy*dy < r2;
}
Technically, yes, a square of 4/3*r will be entirely inside the circle, but that's not the biggest square inside the circle. An inscribed square has sides of sqrt(2)*r.
Regardless, the easiest way to calculate whether the point is inside the circle is to check if the point is less than radius away from the center; see glowcoder's code.

Resources