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

  • SEARCH
  • Home
  • 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 8796061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:32:09+00:00 2026-06-13T23:32:09+00:00

Imagine we have the circle defined by: X^2 + Y^2 = r^2 The origin

  • 0

Imagine we have the circle defined by:

X^2 + Y^2 = r^2

The origin of the circle is 0 and radius = 1. If we draw a horizontal line from the origin moving to the right with coordinates (x1,y1)=(0,0) and (x2,y2) = (2,0) this line should intersect the circle. e.g.

library(plotrix)
plot(0,0,xlim=c(-3,3),ylim=c(-2,2))
draw.circle(0,0,1)
lines(c(0,2),c(0,0))

enter image description here

I have tried to find the intersect of the line with the circle but with no luck. I took
my approach from the this wolfram page and produce the following code but it does not seem to produce the correct result. Can someone please point me to my (no doubt) stupid mistake?

r <- 1
id <- 1:5
x1 <- c(0)
y1 <- c(0)
x2 <- c(2)
y2 <- c(0)
df <- data.frame(id,x1,y1,x2,y2)

df <- transform(df, dx = x2-x1)
df <- transform(df, dy = y2-y1)
df <- transform(df, dr = sqrt(dx^2+dy^2))
df <- transform(df, D  = (x1*y2)-(x2*y1))
df <- transform(df, dysign = sapply(dy,function(x) ifelse(x < 0,-1,1)))
df <- transform(df, newxplus = (D*dy + (dysign*dy) *dx*sqrt(r^2*dr^2-D^2))/dr^2)
df <- transform(df, newxneg  = (D*dy - (dysign*dy) *dx*sqrt(r^2*dr^2-D^2))/dr^2)
df <- transform(df, newyplus = (-D*dx + (abs(dy)) *sqrt(r^2*dr^2-D^2))/dr^2)
df <- transform(df, newyneg  = (-D*dx - (abs(dy)) *sqrt(r^2*dr^2-D^2))/dr^2)

# where newxplus and newxneg are the two x coordinates for the two possible intercepts
# similarly for newyplus and newyneg
df
  • 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-13T23:32:11+00:00Added an answer on June 13, 2026 at 11:32 pm

    You made a typo in your calculation of newxplus, and newxneg.

    The notation sgn*(dy) on the wolfram page you linked is the function sgn* applied to the value dy, i.e. your column dysign, not the column dysign multiplied by dy.

    so:

    # df <- transform(df, newxplus = (D*dy + (dysign*dy)*dx*sqrt(r^2*dr^2-D^2))/dr^2)
    df <- transform(df, newxplus = (D*dy + dysign*dx*sqrt(r^2*dr^2-D^2))/dr^2)
    # df <- transform(df, newxneg  = (D*dy - (dysign*dy)*dx*sqrt(r^2*dr^2-D^2))/dr^2)
    df <- transform(df, newxneg  = (D*dy - dysign*dx*sqrt(r^2*dr^2-D^2))/dr^2)
    

    Giving your x coordinates of the intercepts of -1 and +1.

    Note that the page you linked is for the intersection of an infinite line with the circle which is why you got two intersections, but you can later apply the x/y limits of the lines to the output intersections to filter which ones you want if you are using finite lines.

    Also you mention you’re only using a dataframe for now in the practice (note that the 5 rows you have are always the same…), but when you write your full version of this function I recommend pre-calculating the value sqrt(r^2 * dr^2 - D^2) since it’s used to calculate both the x and y coordinates.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine I have this table: Column A | Column B | Column C ------------------------------
Imagine I have this structure: class Foo { String bar } Now imagine I
Imagine I have a column of a table like this: b - 1 1
Imagine I have a service that looks like this: public interface MyAccountService { boolean
Imagine you have a website with several drop-downs that are populated from the back-end
Imagine you have two tables, with a one to many relationship. For this example,
Imagine you have this: <div class=parent_with_height200px> <div class=left>This is the left floated text, size
Imagine I have abstract base class Shape , with derived classes Circle and Rectangle
Imagine you have this class class Ai1ec_Less_Parser_Controller { /** * @var Ai1ec_Read_Variables_Startegy */ private
Imagine I have this simple table: Table Name: Table1 Columns: Col1 NUMBER (Primary Key)

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.