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

  • Home
  • SEARCH
  • 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 124181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T04:24:17+00:00 2026-05-11T04:24:17+00:00

… and thanks for reading… I’m still learning the ropes so please be forgiving…

  • 0

… and thanks for reading…

I’m still learning the ropes so please be forgiving… 😉

I am writing a function that meshes a solid in space. The mesh is done by using objects of a ‘Node’ class and each node is represented by:

int id double p double r 

Initially I thought that a map would be the way to go: with a map I can make the association between the ‘id’ key and the second key (a pointer to the node object).

Something like this:

int nodeId; Node *node; std::map<int, Node *> NodeMap; 

Then, when I create the nodes I just call the ‘new’ operator. E.g in a for loop I do something like this:

node = new Node(i); // the node constructor sets the id to the value of i. 

and I add the new node to the map:

NodeMap[i] = node; 

But…. I realized that I will need to do a lookup in the map not by first key (the id) but by the p and r parameters (the coordinates of the node).

In other words I will need something that returns the node id given the values of p and r. A map is a perfect container if the lookup is done using the integer first key (id). Does anyone have a suggestion on how to solve this particular problem?

Thanks much! AsvP.

  • 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. 2026-05-11T04:24:18+00:00Added an answer on May 11, 2026 at 4:24 am

    A map<> won’t work. C++ associative containers work on the basis of key equality, and comparing floating-point numbers for equality doesn’t work at all well.

    It sounds like you need to find a node, given x and y. The best way will depend on what you’re trying to accomplish. Are you trying to find the nearest node, given the coordinates, or are you going to calculate coordinates that are very close to a node, and then you need to find the node?

    For the second, you’ll probably be well off sorting the nodes on either the x or y coordinate (I’ll assume the x), and doing a binary search to find which nodes have x coordinates very close to your given x. That will generally select a small number of nodes, which can be searched for the approximately correct y.

    (Of course, if the nodes are in some sort of predictable grid, you should be able to provide some means to calculate directly, like round x and y to nearest integer if you’ve got integral lattice points.)

    If you need to find the closest node, well, that gets a bit complicated. I don’t know enough about this to help much, but there are resources for geometric algorithms.

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

Sidebar

Related Questions

so I did $subject = 'sakdlfjsalfdjslfad <a href=something/8230>lol is that true?</a> lalalala'; $subject =
CGI.escapeHTML is pretty bad, but CGI.unescapeHTML is completely borked. For example: require 'cgi' CGI.unescapeHTML('&#8230;')
I have an element like this: <span class=tool_tip title=The full title>The ful&#8230;</span> This seems
(tl;dr: see summary at the bottom.) I am implementing an application that pulls content
When I use the list function: el_nino_1974_2000_all <- list() for (k in seq_along(el_nino_start_month)){ el_nino_1974_2000_all[[k]]
I have this xml <entry id=1008 section=articles> <excerpt><p>&#8230; in Richtung „Aus für Tierversuche. Kosmetik-Fertigprodukte
I see that some rss on xml have strange strings. For example, ... is
English is not my native language. I need a software to spellcheck and correct
what about this one: I want to format the currentTime displayed by a videoPlayer
I want to sign a message according to the RSA-SHA1 Signature Method in OAuth

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.