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 8385563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:42:08+00:00 2026-06-09T17:42:08+00:00

I have one line segment formed by two vectors, let’s say v1 and v2,

  • 0

I have one line segment formed by two vectors, let’s say v1 and v2, a vector v3 and an angle a. How do I write a method in Java (I’m also using Apache Commons Math to represent a vector) which gives me a vector v4, so that the line segments v1-v2 and v3-v4 are at angle a? There are infinite v4 elements, it would even be better if I could give a size to that method so that the line segment v3-v4 has that size. (all in 2d space, angle can be radians or degrees, doesn’t matter)

Edit: as promised I have included an image of the problem I’m trying to solve. I have a line segment defined by 2 vectors (the line is a bit longer but that doesn’t matter), an angle, and a third point. I need to draw the second line which intersects the first one at angle a. Since all lines in Javafx (which I’m using here) are drawn by defining two points, I needed to find the red point (or any of the possible ones).
visual representation of the problem

Edit: Using Ali’s answer I got the following method which does what I need:

public Pair<Vector2D, Vector2D> calculateFourthPoint(Vector2D v1, Vector2D v2, Vector2D v3, double angleInDegrees) {
    Vector2D r = v1.subtract(v2);
    double rx = r.getX();
    double ry = r.getY();
    double angle = toRadians(angleInDegrees);

    double a = pow(rx, 2) + pow(ry, 2);
    double b = 2 * sqrt(pow(rx, 2) + pow(ry, 2)) * cos(angle) * rx;
    double c = pow(rx, 2) * pow(cos(angle), 2) + pow(ry, 2) * pow(cos(angle), 2) - pow(ry, 2);
    double discriminant = sqrt(pow(b, 2) - (4 * a * c));

    double sx1 = (-b + discriminant) / (2 * a);
    double sx2 = (-b - discriminant) / (2 * a);

    double sy1 = sqrt(1 - pow(sx1, 2));
    double sy2 = sqrt(1 - pow(sx2, 2));

    Vector2D s1 = new Vector2D(sx1, sy1);
    Vector2D s2 = new Vector2D(sx2, sy2);

    Vector2D v4_1 = v3.subtract(s1);
    Vector2D v4_2 = v3.subtract(s2);

    return new Pair<Vector2D, Vector2D>(v4_1, v4_2);
}
  • 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-09T17:42:09+00:00Added an answer on June 9, 2026 at 5:42 pm

    I don’t know Apache Commons Math so I am writing in pseudo code. Let vx and vy denote the x and y components of vector v, respectively.

    Let r=v1-v2 and s=v3-v4. You have 2 unknowns (namely sx and sy; and v4=v3-s) so you need 2 equations. These should be:

    dot_product(r,s)=length(r)*cos a // forces the desired angle
    
    dot_product(s,s)=1 // just sets the length of s to 1
    

    To spell it out, the above equations are:

    (1)    rx*sx + ry*sy = sqrt(rx^2+ry^2)*cos a
    
    (2)    sx^2 + sy^2 = 1
    

    The first equation is linear in both sx and sy. Let’s eliminate sy from the first equation (assuming that ry is not zero)

     sy = (1/ry)*(sqrt(rx^2+ry^2)*cos a - rx*sx)
    

    and substitute this sy into the second equation. You get a quadratic equation in sy (I don’t want to write it here because it is complicated) and that has 2 solutions. You get the corresponding sx by substituting the sy values into (assuming rx is not zero):

     sx = (1/rx)*(sqrt(rx^2+ry^2)*cos a - ry*sy).
    

    Finally, v4=v3-s. You get 2 solutions for v4, one for each of the solutions to the quadratic equation. (Degenerate cases, such as r being a null vector, are ignored in my answer.)

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

Sidebar

Related Questions

I have one line (two point (x,y) (x1,y1)) and a rectangle with focus point
In UML sequence diagram a method can have only one return line (at least
I have a file named file with three lines: line one line two line
I have one line in php file like this: <a class=hide-if-no-js onclick=findPosts.open( 'media[]','<?php echo
I have one line of code which seems commented. Basically the thing I want
I mean I have one line and I want to put 2 spinner in
I have a file with one line in it. I create a branch and
I have this code that where I would normally use one line: if (tableView
I have an html deep inside my directory structure inside c:\ . one line
I'm trying to figure out how to have a short, one line conditional statement.

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.