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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:45:51+00:00 2026-06-14T15:45:51+00:00

I would like sample a line hand-drawn by a user on the android screen

  • 0

I would like “sample” a line hand-drawn by a user on the android screen into an array. The x-coordinates would be equidistant and would very likely be the indices of the 1D array.

To give an example of what I mean, if the user draws an approximate sine wave, I want to create an array that can translate that approximate sine wave to yet another graph, or be used in audio synthesis.

I have a basic idea as to an approach, start with an array:

float samples[] = new float[100] // or some other arbitrary number

Then an ontouch method:

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        float x = event.getX();
        float y = event.getY();
        if(event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE){
            // assume we translate x into relative index from 0-99 at this point
            if(!xHasPoint(x, samples)){
                drawNewPoint();
                samples[x] = y;
            }
            invalidate();
            return true;
        }
        else{
            invalidate();
            return false;
        }
    }

private static boolean xHasPoint(float x, float[] a){
    if(a[x] == !null){
         return true;
    }
    else{
         return false;
    }
}

So my question is, can you suggest a better approach to this problem? I foresee having to extrapolate a lot data… looping through the array at the end and assigning null indices mean values from the nearest non-null values, that sort of thing.

On the other hand, if this doesn’t seem wrong, am I missing any important big-picture considerations?

  • 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-14T15:45:52+00:00Added an answer on June 14, 2026 at 3:45 pm

    The only problem is, that once your array is full, you can’t keep adding more points. I would suggest, you go with a growable data structure.

    Say for example, if it’s an ArrayList, you can keep adding any number of points(theoretically).

    I don’t really understand the method hasPoints. Ideally, while drawing itself, you should be simultaneously sampling, and interpolating, and also may be, smoothing the curves.

    Update: Yeah, if that is the case, then you could only try and register a point only when it has moved, say more than 4 pixels, and then somehow interpolate and draw the curve by smoothing it between the previous and the next point. And also, you would need to capture y-points as well I guess.

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

Sidebar

Related Questions

I would like to extract items from this sample html, more specificly, i would
Using the Northwind sample: I would like to create an insert trigger on the
I have a sample dataform and I would like to remove the ability to
I have this sample string where I would like to replace the star with
I would like to implement a template which contains an array of the template
Please I would like your help with the following issue: This is a sample
I would like a same solution like here: Sample but I didn't find a
I would like to create a simple Line Graph like the following, I googled
I would like to write an android app that basically layers an overlay on
After a user edits data in jqGrid, I would like to return a formatted

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.