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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:41:04+00:00 2026-06-11T16:41:04+00:00

Supposed I have the following dataset double * data = (double *) malloc(sizeof(double) *

  • 0

Supposed I have the following dataset

double * data = (double *) malloc(sizeof(double) * 100 * 2);
for (ii = 0; ii < 100; ii++) {
    data[2*ii] = ii;
    data[2*ii + 1] = ii;
}

how can I create a boost polygon from this data?

thanks

  • 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-11T16:41:05+00:00Added an answer on June 11, 2026 at 4:41 pm

    A complete example

    #include <iostream>
    #include <boost/polygon/polygon.hpp>
    #include <vector>
    
    // Some typedefs
    namespace bpl = boost::polygon;
    typedef bpl::polygon_data<double> Polygon;
    typedef bpl::polygon_traits<Polygon>::point_type Point;
    
    int main() {
    
      // Your C-style data (assumed (x,y) pairs)
      double * data = (double *) malloc(sizeof(double) * 100 * 2);
      for (int ii = 0; ii < 100; ii++) {
        data[2*ii] = ii;
        data[2*ii + 1] = ii;
      }
    
      // Convert to points
      std::vector<Point> points;
      for (int i=0;i<100;++i)
        points.push_back(Point(data[2*i],data[2*i+1]));
    
      // Create a polygon
      Polygon polygon;
      polygon.set(points.begin(),points.end());
    
      // Do something with the polygon
      std::cout << "Perimeter : " << bpl::perimeter(polygon) << std::endl;
      std::cout << "Area      : " << bpl::area(polygon) << std::endl;
    
      return 0;
    }
    

    Just to illustrate the flexibility you actually have: with a bit of extra typedef work, its possible to define your own pair-of-doubles point type which can be aliased onto your data, which avoids the intermediate copy…

    #include <iostream>
    #include <boost/polygon/polygon.hpp>
    #include <vector>
    
    // Define a point type which can be aliased to your 'C' points
    struct Pt {
      double x;
      double y;
    };
    
    // Some typedefs
    namespace bpl = boost::polygon;
    typedef bpl::polygon_data<double> Polygon;
    
    // Add the necessary to use Pt
    namespace boost { 
      namespace polygon {
    
        template <> struct geometry_concept<Pt> {typedef point_concept type;};
    
        template <> struct point_traits<Pt> {
          typedef double coordinate_type;
    
          static inline coordinate_type get(const Pt& pt,orientation_2d orient) {
        return (orient == HORIZONTAL ? pt.x : pt.y);
          }
        };
    
        template <> struct point_mutable_traits<Pt> {
          static inline void set(Pt& pt, orientation_2d orient, int value) {
        if(orient == HORIZONTAL)
          pt.x = value;
        else
          pt.y = value;
          }
          static inline Pt construct(double x,double y) {
        Pt r;
        r.x=x;
        r.y=y;
        return r;
          }
        };
      } 
    }
    
    int main() {
    
      // Your C-style data (assumed (x,y) pairs)
      double * data = (double *) malloc(sizeof(double) * 100 * 2);
      for (int ii = 0; ii < 100; ii++) {
        data[2*ii] = ii;
        data[2*ii + 1] = ii;
      }
    
      // Reinterpret your data as an array of Pt
      const Pt*const pts=reinterpret_cast<const Pt*>(data);
    
      // Create a polygon
      Polygon polygon;
      polygon.set(pts,pts+100);
    
      // Do something with the polygon
      std::cout << "Perimeter : " << bpl::perimeter(polygon) << std::endl;
      std::cout << "Area      : " << bpl::area(polygon) << std::endl;
    
      return 0;
    }
    

    And this trend could be continued to a custom polygon class.

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

Sidebar

Related Questions

Supposed I have the following code: <html:link onclick=jQuery('#add').data('name','${name}').dialog('open'); href=#> And with this, if ${name}
I have the following method that is supposed to parse information from an XML
I have the following code. However I get a error. How is this supposed
I have the following element inside a template, which is supposed to create a
Supposed I have the following tables: Sailor(sid, sname, age) Boat(bid, sid) Each boat can
I have following XML generated by serializing a boost::posix_time::ptime structure. I want to create
The following bit of SAS code is supposed to read from a dataset which
How can I filter data from dataset to datatable? like the code-> DataRow[] dr
I have the following code which is supposed to stop anything from happening when
Supposed I have the following string: string str = <tag>text</tag>; And I would like

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.