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;
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
|
show 3 more comments
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
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 onx
values and find the correspondingy
values. If the line is "more vertical", iterate ony
values and find the correspondingx
values.
– Arnaud Denoyelle
Mar 22 at 17:03
|
show 3 more comments
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
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
java graphics awt drawing java-2d
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 onx
values and find the correspondingy
values. If the line is "more vertical", iterate ony
values and find the correspondingx
values.
– Arnaud Denoyelle
Mar 22 at 17:03
|
show 3 more comments
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 onx
values and find the correspondingy
values. If the line is "more vertical", iterate ony
values and find the correspondingx
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
|
show 3 more comments
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 correspondingy
values. If the line is "more vertical", iterate ony
values and find the correspondingx
values.– Arnaud Denoyelle
Mar 22 at 17:03