Get the coordinates at the edge of the screen from a given angle

Antict

I know the startpoint (the middle of the screen) and the angle (in my example 20°). Now I want to know the position on the edge of the screen, like an invisible line is drawn from the center to the edge in the given angle. For better explanation, I included an image:

example

samgak

One way to do this is to calculate a point on a circle with a radius equal to or greater than the maximum diagonal, and then just clip it to the screen boundary.

Using Pythagoras' theorem, the length of the maximum diagonal will be

float d = Math.sqrt((width/2)*(width/2) + (height/2)*(height/2));

So you can calculate the point on the circle like this (angle is in radians clockwise from the top):

float x = Math.sin(angle) * d;
float y = -Math.cos(angle) * d;

Then you have to clip the vector from the origin to the point to each of the 4 sides, e.g for the right and left sides:

if(x > width/2)
{
    float clipFraction = (width/2) / x; // amount to shorten the vector
    x *= clipFraction;
    y *= clipFraction;
}
else if(x < -width/2)
{
    float clipFraction = (-width/2) / x; // amount to shorten the vector
    x *= clipFraction;
    y *= clipFraction;
}

Also do this for height/2 and -height/2. Then finally you can add width/2, height/2 to x and y to get the final position (with the center of the screen being width/2, height/2 not 0,0):

x += width/2
y += height/2

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get the coordinates at the edge of the screen from a given angle

From Dev

How to get object coordinates from screen coordinates?

From Dev

Get angle from OpenCV Canny edge detector

From Dev

Delphi, TTreeView: how to get the screen coordinates of the given node and its icon?

From Dev

How to get world coordinates from screen coordinates in Vispy

From Dev

How can I get 'edge' points (furthest edge coordinates) from a list of coordinates

From Dev

Get values of given coordinates in Matlab

From Dev

Get the center coordinates of phone screen

From Dev

Get Screen-Coordinates of a QuickControl

From Dev

Get the center coordinates of phone screen

From Dev

Get coordinates (screen) of GridLayout items

From Dev

How to use trig on screen coordinates to calculate angle between points

From Dev

How to calculate transformation from screen coordinates to isometric screen coordinates?

From Dev

Calculating screen coordinates of horizontal edge of bounding box in three.js

From Dev

Get Maximum X and Y coordinates from Android Screen from command line

From Dev

Get coordinates from map

From Dev

Get screen coordinates of a node in javaFX 8

From Dev

Get Canvas X and Y coordinates and show on screen

From Dev

Get the coordinates of visible part of screen when zoomed in

From Dev

How to get coordinates of touch screen points in ogl?

From Dev

Find number of rectangles from a given set of coordinates

From Dev

How to print the coordinates from the given string?

From Dev

Pass screen coordinates from button to parent

From Dev

Calculating Screen Coordinates from +/- Cartesian Input Values

From Dev

Determine screen coordinates from point in DirectX world

From Dev

Get distance between screen edge and webpage

From Dev

Dihedral/Torsion Angle From Four Points in Cartesian Coordinates in Python

From Dev

Find an angle representing the direction of travel from origin coordinates

From Dev

How can I get a component's position on screen (screen coordinates)

Related Related

  1. 1

    Get the coordinates at the edge of the screen from a given angle

  2. 2

    How to get object coordinates from screen coordinates?

  3. 3

    Get angle from OpenCV Canny edge detector

  4. 4

    Delphi, TTreeView: how to get the screen coordinates of the given node and its icon?

  5. 5

    How to get world coordinates from screen coordinates in Vispy

  6. 6

    How can I get 'edge' points (furthest edge coordinates) from a list of coordinates

  7. 7

    Get values of given coordinates in Matlab

  8. 8

    Get the center coordinates of phone screen

  9. 9

    Get Screen-Coordinates of a QuickControl

  10. 10

    Get the center coordinates of phone screen

  11. 11

    Get coordinates (screen) of GridLayout items

  12. 12

    How to use trig on screen coordinates to calculate angle between points

  13. 13

    How to calculate transformation from screen coordinates to isometric screen coordinates?

  14. 14

    Calculating screen coordinates of horizontal edge of bounding box in three.js

  15. 15

    Get Maximum X and Y coordinates from Android Screen from command line

  16. 16

    Get coordinates from map

  17. 17

    Get screen coordinates of a node in javaFX 8

  18. 18

    Get Canvas X and Y coordinates and show on screen

  19. 19

    Get the coordinates of visible part of screen when zoomed in

  20. 20

    How to get coordinates of touch screen points in ogl?

  21. 21

    Find number of rectangles from a given set of coordinates

  22. 22

    How to print the coordinates from the given string?

  23. 23

    Pass screen coordinates from button to parent

  24. 24

    Calculating Screen Coordinates from +/- Cartesian Input Values

  25. 25

    Determine screen coordinates from point in DirectX world

  26. 26

    Get distance between screen edge and webpage

  27. 27

    Dihedral/Torsion Angle From Four Points in Cartesian Coordinates in Python

  28. 28

    Find an angle representing the direction of travel from origin coordinates

  29. 29

    How can I get a component's position on screen (screen coordinates)

HotTag

Archive