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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:25:11+00:00 2026-06-12T06:25:11+00:00

I’m trying to detecting wether a given point is inside a closed SVG path

  • 0

I’m trying to detecting wether a given point is inside a closed SVG path in Objective-C. I’m having trouble figuring out how to do the math.

I have a path’s coordinates and I’d like to determine wether a random point is inside or outside the path.

Here’s an example of a path’s coordinates:

"M673 460 c2 0 4 -1 5 -2 1 -1 2 -2 2 -4 0 -2 0 -3 0 -3 0 0 -3 1 -5 1 -3 1 -5 2 -5 3 0 1 0 3 0 4 1 0 2 1 3 1z:"

I’m aware of the CoreGraphics’s containsPoint: method, but I’d like to avoid using this method.

How can I do this by writing my own method?

EDIT:

I’m trying to avoid containsPoint: because the function seems to crash on some coordinates / paths when using it. It looks quite random when it crashes and when it doesn’t.

Here are some examples of paths where containsPoint: makes the app crash:

"M661 446 c1 -1 3 -1 4 -1 1 -1 2 -2 2 -4 0 -2 0 -2 -2 -2 0 1 -2 1 -3 1 -2 0 -3 1 -3 2 0 1 0 2 0 3 0 0 1 1 2 1z" 
"M535 460 c0 0 1 -1 1 -2 1 -2 0 -3 -1 -3 0 0 -1 0 -2 1 0 1 0 2 0 3 1 0 1 1 2 1z" 

Xcode breaks with and EXC_BAD_ACCESS in the assembly by the following two functions: get_y_inflections and get_cubic_coefficients.

EDIT 2:

I posted a new question about the containsPoint: problem.

  • 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-12T06:25:12+00:00Added an answer on June 12, 2026 at 6:25 am

    So, as i needed a Polygon/Interpolation from a Curved Path myself, i might have a solution for your problem as well:

    The two ‘Public’ Functions:

    CGPathRef CGPathCreatePolygonPath(CGPathRef path, int quality);

    Creates an Path with only Line-Elements, quality is the number of segments a curve is split into

    BOOL CGPathContainsPointInterpolated(CGPathRef path, const CGAffineTransform *m, CGPoint point, bool eoFill, int quality);

    Does CGPathContainsPoint and Interpolation in one step, quality is again the number of segments a curve is split into.

    Here is the implementation.

    typedef struct {
        CGMutablePathRef path;
        int quality;
    } InterpolationInfo;
    
    static inline float cubeInterp(float t, float p0, float p1, float p2, float p3) {
        return powf(1-t, 3)*p0 + 3*powf(1-t, 2)*t*p1 + 3*(1-t)*powf(t, 2)*p2 + powf(t, 3)*p3;
    }
    
    static void pointsForCubeCurve(CGPoint cp0, CGPoint cp1, CGPoint cp2, CGPoint ep, CGPoint *buffer, int numberPoints) {
        for (int i = 0; i<numberPoints; i++) {
            float t = (i+1)/(float)numberPoints;
            buffer[i] = CGPointMake(cubeInterp(t, cp0.x, cp1.x, cp2.x, ep.x), cubeInterp(t, cp0.y, cp1.y, cp2.y, ep.y));
        }
    }
    
    static inline float quadInterp(float t, float p0, float p1, float p2) {
        return powf(1-t, 2)*p0 + 2*(1-t)*t*p1 + powf(t, 2)*p2;
    }
    
    static void pointsForQuadCurve(CGPoint cp0, CGPoint cp, CGPoint ep, CGPoint *buffer, int numberPoints) {
        for (int i = 0; i<numberPoints; i++) {
            float t = (i+1)/(float)numberPoints;
            buffer[i] = CGPointMake(quadInterp(t, cp0.x, cp.x, ep.x), quadInterp(t, cp0.x, cp.x, ep.x));
        }
    }
    
    static void CGPathElementConvertToPolygon(void *info, const CGPathElement *element) {
        InterpolationInfo *interpInfo = info;
        switch (element->type) {
            case kCGPathElementMoveToPoint:
                CGPathMoveToPoint(interpInfo->path, NULL, element->points[0].x, element->points[0].y);
                break;
            case kCGPathElementAddLineToPoint:
                CGPathAddLineToPoint(interpInfo->path, NULL, element->points[0].x, element->points[0].y);
                break;
            case kCGPathElementAddQuadCurveToPoint: {
                int nr = interpInfo->quality;
                CGPoint buffer[nr];
                pointsForQuadCurve(CGPathGetCurrentPoint(interpInfo->path), element->points[0], element->points[1], buffer, nr);
                for (int i = 0; i<nr; i++) {
                    CGPathAddLineToPoint(interpInfo->path, NULL, buffer[i].x, buffer[i].y);
                }
                break;
            }
            case kCGPathElementAddCurveToPoint: {
                int nr = interpInfo->quality;
                CGPoint buffer[nr];
                pointsForCubeCurve(CGPathGetCurrentPoint(interpInfo->path), element->points[0], element->points[1], element->points[2], buffer, nr);
                for (int i = 0; i<nr; i++) {
                    CGPathAddLineToPoint(interpInfo->path, NULL, buffer[i].x, buffer[i].y);
                }
                break;
            }
            case kCGPathElementCloseSubpath:
                CGPathCloseSubpath(interpInfo->path);
                break;
            default:
                break;
        }
    }
    
    static CGPathRef CGPathCreatePolygonPath(CGPathRef path, int quality) {
        CGMutablePathRef newPath = CGPathCreateMutable();
        InterpolationInfo info;
        info.path = newPath;
        info.quality = quality;
        CGPathApply(path, &info, CGPathElementConvertToPolygon);
        return newPath;
    }
    
    static BOOL CGPathContainsPointInterpolated(CGPathRef path, const CGAffineTransform *m, CGPoint point, bool eoFill, int quality) {
        CGPathRef polygon = CGPathCreatePolygonPath(path, quality);
        BOOL returnValue = CGPathContainsPoint(polygon, m, point, eoFill);
        CGPathRelease(polygon);
        return returnValue;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to select an H1 element which is the second-child in its group

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.