How can I get the points between two points on a line?Collision detection with complex shapesPrecise subpixel line drawing algorithm (rasterization algorithm)How to deal with “java.lang.OutOfMemoryError: Java heap space” error?How can I concatenate two arrays in Java?How can I determine whether a 2D Point is within a Polygon?Fastest way to determine if an integer's square root is an integerHow can I create an executable JAR with dependencies using Maven?How to get an enum value from a string value in Java?How can I convert a stack trace to a string?Can't start Eclipse - Java was started but returned exit code=13how to bypass calling of parent class paint methodExtending Graphics class with drawLine(double, double, double, double)

Magical attacks and overcoming damage resistance

Restricting the options of a lookup field, based on the value of another lookup field?

What does "function" actually mean in music?

How bug prioritization works in agile projects vs non agile

Is there metaphorical meaning of "aus der Haft entlassen"?

Can I criticise the more senior developers around me for not writing clean code?

Why do games have consumables?

Why is the underscore command _ useful?

Apply a different color ramp to subset of categorized symbols in QGIS?

Nails holding drywall

Philosophical question on logistic regression: why isn't the optimal threshold value trained?

Will I lose my paid in full property

"Whatever a Russian does, they end up making the Kalashnikov gun"? Are there any similar proverbs in English?

Find a stone which is not the lightest one

Why do distances seem to matter in the Foundation world?

Should the Product Owner dictate what info the UI needs to display?

How important is it that $TERM is correct?

What is purpose of DB Browser(dbbrowser.aspx) under admin tool?

Why did C use the -> operator instead of reusing the . operator?

What is this word supposed to be?

Can a stored procedure reference the database in which it is stored?

How exactly does Hawking radiation decrease the mass of black holes?

How to pronounce 'c++' in Spanish

How do I check if a string is entirely made of the same substring?



How can I get the points between two points on a line?


Collision detection with complex shapesPrecise subpixel line drawing algorithm (rasterization algorithm)How to deal with “java.lang.OutOfMemoryError: Java heap space” error?How can I concatenate two arrays in Java?How can I determine whether a 2D Point is within a Polygon?Fastest way to determine if an integer's square root is an integerHow can I create an executable JAR with dependencies using Maven?How to get an enum value from a string value in Java?How can I convert a stack trace to a string?Can't start Eclipse - Java was started but returned exit code=13how to bypass calling of parent class paint methodExtending Graphics class with drawLine(double, double, double, double)






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1















How can I get the points between a start point (x1, y1) and end point (x2, y2) on a line. I need these points to check if it's located in free space or on an obstacle. How can I do this in Java?



 public void paint(Graphics g) 
super.paint(g);
g.drawLine(50, 50, 400, 400);




Is there an existing function that can help me get these points?










share|improve this question



















  • 4





    That's not how you detect collision(there are theoretically infinitely many points). You should use some analytical function to compare the line with obstacle. You should probably add more context.

    – NeplatnyUdaj
    Mar 22 at 16:51












  • Regardless of collision i need to get points of the line

    – zoya
    Mar 22 at 16:55







  • 1





    It is better to use geometry to find out the intersection of your line with various obstacles. If you must get points, you can get points on the line with the formula t*(end - start) + start where t is a number between 0 and 1 representing how far along the line the point is. For half way down your line: x = 0.5 * (400 - 50) + 50 and y = 0.5 * (400 - 50) + 50

    – aptriangle
    Mar 22 at 16:58











  • Well, the API won't give them but you can calculate those pixels with Bresenham algorithm.

    – Arnaud Denoyelle
    Mar 22 at 16:58












  • In short, calculate the slope : if the line is "more horizontal", iterate on x values and find the corresponding y values. If the line is "more vertical", iterate on y values and find the corresponding x values.

    – Arnaud Denoyelle
    Mar 22 at 17:03

















-1















How can I get the points between a start point (x1, y1) and end point (x2, y2) on a line. I need these points to check if it's located in free space or on an obstacle. How can I do this in Java?



 public void paint(Graphics g) 
super.paint(g);
g.drawLine(50, 50, 400, 400);




Is there an existing function that can help me get these points?










share|improve this question



















  • 4





    That's not how you detect collision(there are theoretically infinitely many points). You should use some analytical function to compare the line with obstacle. You should probably add more context.

    – NeplatnyUdaj
    Mar 22 at 16:51












  • Regardless of collision i need to get points of the line

    – zoya
    Mar 22 at 16:55







  • 1





    It is better to use geometry to find out the intersection of your line with various obstacles. If you must get points, you can get points on the line with the formula t*(end - start) + start where t is a number between 0 and 1 representing how far along the line the point is. For half way down your line: x = 0.5 * (400 - 50) + 50 and y = 0.5 * (400 - 50) + 50

    – aptriangle
    Mar 22 at 16:58











  • Well, the API won't give them but you can calculate those pixels with Bresenham algorithm.

    – Arnaud Denoyelle
    Mar 22 at 16:58












  • In short, calculate the slope : if the line is "more horizontal", iterate on x values and find the corresponding y values. If the line is "more vertical", iterate on y values and find the corresponding x values.

    – Arnaud Denoyelle
    Mar 22 at 17:03













-1












-1








-1








How can I get the points between a start point (x1, y1) and end point (x2, y2) on a line. I need these points to check if it's located in free space or on an obstacle. How can I do this in Java?



 public void paint(Graphics g) 
super.paint(g);
g.drawLine(50, 50, 400, 400);




Is there an existing function that can help me get these points?










share|improve this question
















How can I get the points between a start point (x1, y1) and end point (x2, y2) on a line. I need these points to check if it's located in free space or on an obstacle. How can I do this in Java?



 public void paint(Graphics g) 
super.paint(g);
g.drawLine(50, 50, 400, 400);




Is there an existing function that can help me get these points?







java graphics awt drawing java-2d






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 at 2:25









Andrew Thompson

154k29166352




154k29166352










asked Mar 22 at 16:44









zoyazoya

11




11







  • 4





    That's not how you detect collision(there are theoretically infinitely many points). You should use some analytical function to compare the line with obstacle. You should probably add more context.

    – NeplatnyUdaj
    Mar 22 at 16:51












  • Regardless of collision i need to get points of the line

    – zoya
    Mar 22 at 16:55







  • 1





    It is better to use geometry to find out the intersection of your line with various obstacles. If you must get points, you can get points on the line with the formula t*(end - start) + start where t is a number between 0 and 1 representing how far along the line the point is. For half way down your line: x = 0.5 * (400 - 50) + 50 and y = 0.5 * (400 - 50) + 50

    – aptriangle
    Mar 22 at 16:58











  • Well, the API won't give them but you can calculate those pixels with Bresenham algorithm.

    – Arnaud Denoyelle
    Mar 22 at 16:58












  • In short, calculate the slope : if the line is "more horizontal", iterate on x values and find the corresponding y values. If the line is "more vertical", iterate on y values and find the corresponding x values.

    – Arnaud Denoyelle
    Mar 22 at 17:03












  • 4





    That's not how you detect collision(there are theoretically infinitely many points). You should use some analytical function to compare the line with obstacle. You should probably add more context.

    – NeplatnyUdaj
    Mar 22 at 16:51












  • Regardless of collision i need to get points of the line

    – zoya
    Mar 22 at 16:55







  • 1





    It is better to use geometry to find out the intersection of your line with various obstacles. If you must get points, you can get points on the line with the formula t*(end - start) + start where t is a number between 0 and 1 representing how far along the line the point is. For half way down your line: x = 0.5 * (400 - 50) + 50 and y = 0.5 * (400 - 50) + 50

    – aptriangle
    Mar 22 at 16:58











  • Well, the API won't give them but you can calculate those pixels with Bresenham algorithm.

    – Arnaud Denoyelle
    Mar 22 at 16:58












  • In short, calculate the slope : if the line is "more horizontal", iterate on x values and find the corresponding y values. If the line is "more vertical", iterate on y values and find the corresponding x values.

    – Arnaud Denoyelle
    Mar 22 at 17:03







4




4





That's not how you detect collision(there are theoretically infinitely many points). You should use some analytical function to compare the line with obstacle. You should probably add more context.

– NeplatnyUdaj
Mar 22 at 16:51






That's not how you detect collision(there are theoretically infinitely many points). You should use some analytical function to compare the line with obstacle. You should probably add more context.

– NeplatnyUdaj
Mar 22 at 16:51














Regardless of collision i need to get points of the line

– zoya
Mar 22 at 16:55






Regardless of collision i need to get points of the line

– zoya
Mar 22 at 16:55





1




1





It is better to use geometry to find out the intersection of your line with various obstacles. If you must get points, you can get points on the line with the formula t*(end - start) + start where t is a number between 0 and 1 representing how far along the line the point is. For half way down your line: x = 0.5 * (400 - 50) + 50 and y = 0.5 * (400 - 50) + 50

– aptriangle
Mar 22 at 16:58





It is better to use geometry to find out the intersection of your line with various obstacles. If you must get points, you can get points on the line with the formula t*(end - start) + start where t is a number between 0 and 1 representing how far along the line the point is. For half way down your line: x = 0.5 * (400 - 50) + 50 and y = 0.5 * (400 - 50) + 50

– aptriangle
Mar 22 at 16:58













Well, the API won't give them but you can calculate those pixels with Bresenham algorithm.

– Arnaud Denoyelle
Mar 22 at 16:58






Well, the API won't give them but you can calculate those pixels with Bresenham algorithm.

– Arnaud Denoyelle
Mar 22 at 16:58














In short, calculate the slope : if the line is "more horizontal", iterate on x values and find the corresponding y values. If the line is "more vertical", iterate on y values and find the corresponding x values.

– Arnaud Denoyelle
Mar 22 at 17:03





In short, calculate the slope : if the line is "more horizontal", iterate on x values and find the corresponding y values. If the line is "more vertical", iterate on y values and find the corresponding x values.

– Arnaud Denoyelle
Mar 22 at 17:03












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55304266%2fhow-can-i-get-the-points-between-two-points-on-a-line%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55304266%2fhow-can-i-get-the-points-between-two-points-on-a-line%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?