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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:45:25+00:00 2026-06-07T08:45:25+00:00

I need to calculate the distance between 2 points on a plot. I am

  • 0

I need to calculate the distance between 2 points on a plot.

I am using the method below to achive this need. I tried the others methods but this is the only one that the point is actually plot. On others methods it always return 0.

-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index 


  NSDecimal plotPoint[2];
        CPTPlotSpace *thePlotSpace = plot.plotSpace;
        CPTPlotArea *thePlotArea   = plot.plotArea;
        CPTCoordinate independentCoord = (NO ? CPTCoordinateY : CPTCoordinateX);

        plotPoint[independentCoord] = [plot cachedDecimalForField:CPTBarPlotFieldBarLocation recordIndex:0];

        CGPoint basePoint;

        basePoint = [plot convertPoint:[thePlotSpace plotAreaViewPointForPlotPoint:plotPoint] fromLayer:thePlotArea];

        plotPoint[independentCoord] = [plot cachedDecimalForField:CPTBarPlotFieldBarLocation recordIndex:1];

        CGPoint basePoint2;

        basePoint2 = [plot convertPoint:[thePlotSpace plotAreaViewPointForPlotPoint:plotPoint] fromLayer:thePlotArea];


        int valor; 
        valor =  basePoint2.x - basePoint.x;

The code above works almost always but i am getting EXC_BAD_ACESS that comes from this code above.

When i comment the code, the exc_bad_acess never occur

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000004
Crashed Thread:  0

Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   Foundation                      0x32f7be56 NSIntegerDivide + 98
1   Foundation                      0x32f7f9e0 NSDecimalDivide + 216
2   InfoTOS007                      0x000e198c CPTDecimalDivide (CPTUtilities.m:496)
3   InfoTOS007                      0x000fd0c8 -[CPTXYPlotSpace     viewCoordinateForViewLength:linearPlotRange:plotCoordinateValue:] (CPTXYPlotSpace.m:384)
4   InfoTOS007                      0x000fd66a -[CPTXYPlotSpace plotAreaViewPointForPlotPoint:] (CPTXYPlotSpace.m:449)
5   InfoTOS007                      0x000bea38 -[GraficoEmbarqueDescarga dataLabelForPlot:recordIndex:] (GraficoEmbarqueDescarga.m:249)
6   InfoTOS007                      0x000ce192 -[CPTPlot relabel] (CPTPlot.m:1016)
7   InfoTOS007                      0x000cb868 -[CPTPlot layoutSublayers] (CPTPlot.m:402)
8   QuartzCore                      0x34272f92 CA::Layer::layout_if_needed(CA::Transaction*) + 210
9   QuartzCore                      0x34277114 CA::Context::commit_transaction(CA::Transaction*) + 220
10  QuartzCore                      0x34276e50 CA::Transaction::commit() + 308
11  QuartzCore                      0x3426ed7e CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 50
12  CoreFoundation                  0x344deb44 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 12
13  CoreFoundation                  0x344dcd80 __CFRunLoopDoObservers + 252
14  CoreFoundation                  0x344dd0da __CFRunLoopRun + 754
15  CoreFoundation                  0x344604d6 CFRunLoopRunSpecific + 294
16  CoreFoundation                  0x3446039e CFRunLoopRunInMode + 98
17  GraphicsServices                0x30d4bfc6 GSEventRunModal + 150
18  UIKit                           0x32a2873c UIApplicationMain + 1084
19  InfoTOS007                      0x000b3468 main (main.m:16)
20  InfoTOS007                      0x000b340c start + 32
  • 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-07T08:45:26+00:00Added an answer on June 7, 2026 at 8:45 am

    It looks like the problem is that your never setting plotPoint[dependentCoord], so it is trying to convert an undefined value to plot coordinates. Just set it to a value within the range of your graph, if all your worried about is the X axis, then the Y axis value doesn’t matter. I haven’t tried compiling the following, but it looks right.

      NSDecimal plotPoint[2];
      CPTPlotSpace *thePlotSpace = plot.plotSpace;
      CPTPlotArea *thePlotArea   = plot.plotArea;
      CPTCoordinate independentCoord =  CPTCoordinateX;
      CPTCoordinate dependentCoord =  CPTCoordinateY;
    
      plotPoint[independentCoord] = [plot cachedDecimalForField:CPTBarPlotFieldBarLocation recordIndex:0];
      plotPoint[dependentCoord] = CPTDecimalFromInt(1);
    
      CGPoint basePoint;
      basePoint = [plot convertPoint:[thePlotSpace plotAreaViewPointForPlotPoint:plotPoint] fromLayer:thePlotArea];
    
      plotPoint[independentCoord] = [plot cachedDecimalForField:CPTBarPlotFieldBarLocation recordIndex:1];
       CGPoint basePoint2;
       basePoint2 = [plot convertPoint:[thePlotSpace plotAreaViewPointForPlotPoint:plotPoint] fromLayer:thePlotArea];
    
        int valor; 
        valor =  basePoint2.x - basePoint.x;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to calculate the distance between two points, but not in the regular
Hy! I need to calculate the distance between 2 GPS Points. I read this
I need the ability to calculate walking distance between 2 points without calling an
i need to calculate the distance between two CGPoint s. I refered this and
Hi I have the need to calculate the distance between two points having the
I need to create a class which calculates the distance between two points. I
I need to calculate the distance (in meters and miles) between two coordinates given
I'm writing an application that will calculate the distance and cost between two points.
Distance between two points: sqrt((x1-x2)^2 + (y1-y2)^2) Is there a way to do this
The code below is used to calculate the miles between two cities. In this

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.