Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7951337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:31:49+00:00 2026-06-04T02:31:49+00:00

Simply put, I have: A viewport rectangle where (0,0) is the bottom-left corner, (1,1)

  • 0

Simply put, I have:

  • A viewport rectangle where (0,0) is the bottom-left corner, (1,1) is the top-right and (0.5,0.5) is the centre of the screen.
  • A point (a,b) which is outside of the rectangle.

This is in viewport coordinates so +X is right, +Y is up on the screen.

And I need a function which takes these parameters and returns the point on the edge of the rectangle where the line (between the centre of the rectangle (0.5,0.5) and the point (a,b)) intersects it.

I know how to do this on paper with given coordinates but I just can’t figure it out when it comes down to code. Also, I realise questions like this have been addressed in different threads – but I can’t find a simple input to output function anywhere.

I’m doing this in the Unity3D engine so preferably in Javascript but any language or pseudocode would be a great help as I can probably hand convert it.

EDIT
To clarify, I’m looking for something like:

function IntersectFromViewportCenter(x : float, y : float) {
    ...
    return Point(x1, y1);
}

Where (x,y) is the point outside of the circle and (x1,y1) is the intersection point.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:31:51+00:00Added an answer on June 4, 2026 at 2:31 am

    Shift all system to be centered at point (0,0). Calc intersection of ray from origin to (shifted) point (x’,y’) with box (-1,-1)-(1,1). Scale and shift back. I did not consider trivial case with point inside the box ( is it needed?)

    x = x - 0.5
    y = y - 0.5
    if Abs(x) >= Abs(y) then  //vertical box edge
      y1 = y/x  //care with case both y and x = 0
      x1 = Sign(x) //+-1
    else   // horizontal edge
      x1 = x/y
      y1 = Sign(y)
    
    x1 = 0.5*x1 + 0.5
    y1 = 0.5*y1 + 0.5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Simply put I want what http://www.reddit.com/ and http://news.ycombinator.com/ have to the left of every
I have a new project which simply put, is an attempt to formalize the
I have a large data set of nucleotide sequences (long strings simply put) which
Simply put: I have a database design in my head and I now want
Simply put, I have a string with a prefix msg followed by some numbers
Simply put: I have a table with 2 columns: one is username and other
Simply put, I have a page called 'products' (not a post, but a page,
Simply put, I have a series of videos with check boxes in a gridview.
I have a class hierarchy that can be simply put like this: struct Parent
I currently have to validate custom Field Objects for my application. Simply put, each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.