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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:49:13+00:00 2026-06-02T07:49:13+00:00

Essentially I’m trying to calculate the bisector line between two points. I’ve got two

  • 0

Essentially I’m trying to calculate the bisector line between two points. I’ve got two methods, one works the other doesn’t. I can’t quite figure out why the other one doesn’t work. The one that works is a little more computationally intensive and since this routine is run a lot, I’d like to use the simpler one… except it doesn’t work. I’m probably missing something simple but I find this amusing since I seem to have a better grasp of trig than I do of high school algebra.

Note: the function is passed the end points (endPoint1, endPoint2).
Here’s the one that works (using trig to calculate the bisector):

CGPoint midPoint = CGPointMake((endPoint1.x + endPoint2.x) / 2, (endPoint1.y + endPoint2.y) / 2);

//Normalize an end point
CGPoint nPoint = CGPointMake(endPoint1.x - endPoint2.x, endPoint1.y - endPoint2.y);

//Find theta and rotate 90°
CGFloat theta = atanf(nPoint.y / nPoint.x);
if (nPoint.x < 0.0f) theta += M_PI;
else if (nPoint.x > 0.0f && nPoint.y < 0.0f) theta += (M_PI * 2);
theta += M_PI_2;

//Calculate another point along new theta and de-normalize the point
CGPoint centerPoint = CGPointMake(cosf(theta) * 10, sinf(theta) * 10);
centerPoint.x += midPoint.x;
centerPoint.y += midPoint.y;

//Create the line definition
LineDef def = LineDefForPoints(midPoint, centerPoint);

Here’s the one that doesn’t, but I’d like it to:

CGPoint midPoint = CGPointMake((endPoint1.x + endPoint2.x) / 2, (endPoint1.y + endPoint2.y) / 2);
//Calculate the slope and invert
CGFloat m = (endPoint1.y - endPoint2.y) / (endPoint1.x - endPoint2.x);
//Take the negative reciprocal 
m = -1/m;       

//Calculate another point on the line        
CGPoint centerPoint = CGPointMake(midPoint.x + 10, midPoint.y + (m * 10));
//Create the line definition
LineDef def = LineDefForPoints(midPoint, centerPoint);

So I’d swear this should work. The change in Y is equal to m times the change in x. I’ve calculated the mid point, figured out the slope of the perpendicular line and calculated another point on that line. However the line definitions created aren’t equivalent when given the same end points, so I’m missing something.

By the way, LindeDef is a simple struct with three CGFloat variables for the a, b & c components of a straight line. And creating a LineDef from two points is trivial (I happen to be using a block to do this):

LineDef (^LineDefForPoints)(CGPoint, CGPoint) = ^LineDef(CGPoint p1, CGPoint p2){
    LineDef line = {0,0,0};
    line.a = p2.y - p1.y;
    line.b = p1.x - p2.x;
    line.c = line.a*p1.x + line.b*p1.y;
    return line;
};
  • 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-02T07:49:14+00:00Added an answer on June 2, 2026 at 7:49 am

    Dammit, it was something simple. I reformatted my actual production code so I could put it on Stack Exchange and in the process edited out my mistake. The code I posted in the question actually works perfectly. Originally the line: m = -1 / m; was folded into the original assignment like so: CGFloat m = -1 / (endPoint1.y - endPoint2.y) / (endPoint1.x - endPoint2.x);. Of course, now the problem is obvious…I forgot parenthesis. I separated the line into two in stack exchange so I could explain my ‘reasoning’ in the comments, hoping to find the problem.

    Sorry, for all the trouble.

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

Sidebar

Related Questions

Essentially what I want to do is select the most recent message between one
Essentially what I'm trying to do is fairly simple....pass more than one parameter (4
Essentially, what I want to do (in DirectX) is to take two partially-transparent images
Essentially, what I'm trying to do is to check the last access time of
Essentially I've got a table holding user data, all of which is AES encrypted
Essentially Im trying to get many many java clients connect to a socket on
Essentially the title of this question explains the essense of what I am trying
Essentially, what I'm trying to do is to load/draw a map from a Tiled
Essentially, I'm trying to achieve the affect of text-align:justify but with floating block elements.
Essentially what I'm trying to do at this point is build a program to

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.