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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:10:16+00:00 2026-06-13T20:10:16+00:00

I have N lines that are defined by a y-intercept and an angle, q.

  • 0

I have N lines that are defined by a y-intercept and an angle, q. The constraint is that all N lines must intersect at one point. The equations I can come up with to eventually get the constraint are these:

Y = tan(q(1))X + y(1)
Y = tan(q(2))X + y(2)
...

I can, by hand, get the constraint if N = 3 or 4 but I am having trouble just getting one constraint if N is greater than 4. If N = 3 or 4, then when I solve the equations above for X, I get 2 equations and then can just set them equal to each other. If N > 4, I get more than 2 equations that equal X and I dont know how to condense them down into one constraint. If I cannot condense them down into one constraint and am able to solve the optimization problem with multiple constraints that are created dynamically (depending on the N that is passed in) that would be fine also.

To better understand what I am doing I will show how I get the constraints for N = 3. I start off with these three equations:

Y = tan(q(1))X + y(1)
Y = tan(q(2))X + y(2)
Y = tan(q(3))X + y(3)

I then set them equal to each other and get these equations:

tan(q(1))X + y(1) = tan(q(2))X + y(2)
tan(q(2))X + y(2) = tan(q(3))X + y(3)

I then solve for X and get this constraint:

(y(2) - y(1)) / (tan(q(1)) - tan(q(2))) = (y(3) - y(2)) / (tan(q(2)) - tan(q(3)))

Notice how I have 2 equations to solve for X. When N > 4 I end up with more than 2. This is OK if I am able to dynamically create the constraints and then call an optimization function in MATLAB that will handle multiple constraints but so far have not found one.

  • 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-13T20:10:17+00:00Added an answer on June 13, 2026 at 8:10 pm

    You say the optimization algorithm needs to adjust q such that the “real” problem is minimized while the above equations also hold.

    Note that the fifth Euclid axoim ensures that all lines will always intersect with all other lines, unless two qs are equal but the corresponding y0s are not. This last case is so rare (in a floating point context) that I’m going to skip it here, but for added robustness, you should eventually include it.

    Now, first, think in terms of matrices. Your constraints can be formulated by the matrix equation:

    y = tan(q)*x + y0
    

    where q, y and y0 are [Nx1] matrices, x an unknown scalar. Note that y = c*ones(N,1), e.g., a matrix containing only the same constant. This is actually a non-linear constraint — that is, it cannot be expressed as

    A*q <= b   or   A*q == b
    

    with A some design matrix and b some solution vector. So, you’ll have to write a function defining this non-linear constraint, which you can pass on to an optimizer like fmincon. From the documentation:

    x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon) subjects the
    minimization to the nonlinear inequalities c(x) or equalities ceq(x)
    defined in nonlcon. fmincon optimizes such that c(x) ≤ 0 and ceq(x) =
    0. If no bounds exist, set lb = [] and/or ub = [].

    Note that you were actually going in the right direction. You can solve for the x-location of the intersection for any pair of lines q(n),y0(n) and q(m),y0(m) with the equation:

    x(n,m) = (y0(n)-y0(m)) / (q(m)-q(n))
    

    Your nonlcon function should find x for all possible pairs n,m, and check if they are all equal. You can do this conveniently something like so:

    function [c, ceq] = nonlcon(q, y0)
        % not using inequalities
        c = -1; % NOTE: setting it like this will always satisfy this constraint
    
        % compute tangents 
        tanq = tan(q);
    
        % compute solutions to x for all pairs 
        x = bsxfun(@minus, y0, y0.') ./ -bsxfun(@minus, tanq, tanq.');
    
        % equality contraints: they all need to be equal 
        ceq = diff(x(~isnan(x))); % NOTE: if all(ceq==0), converged.
    
    end
    

    Note that you’re not actually solving for q explicitly (or need the y-coordinate of the intersection at all) — that is all fmincon‘s job.

    You will need to do some experimenting, because sometimes it is sufficient to define

    x = x(~isnan(x));
    ceq = norm(x-x(1)); % e.g., only 1 equality constraint
    

    which will be faster (less derivatives to compute), but other problems really need

    x = x(~isnan(x));
    ceq = x-x(1); % e.g., N constraints
    

    or similar tricks. It really depends on the rest of the problem how difficult the optimizer will find each case.

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

Sidebar

Related Questions

I want to match all lines that have any uppercase characters in them but
I have line that is defined as two points. start = (xs,ys) end =
I have a set of lines that define a W shape. On each line
I have some text lines like that : vt_wildshade2^508^508 vt_ailleurs2^1188^1188 ... vt_high2^13652^13652 Is it
I have a huge file that has some lines that need to have a
I have a file that contain lines that looks like this: >AF001546_1 [88 -
I have a 100Mb file with roughly 10million lines that I need to parse
I have a data source with about 2000 lines that look like the following:
Basic question here - I have many lines of code that look something like:
I have a file with my lines and I want to compare lines that

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.