Questions tagged [path-2d]

Path2D is an interface used to declare two dimensional paths on an HTML element

Path2D is an interface of the Canvas 2D API used to declare two dimensional objects that can be drawn on an HTML5 <canvas>.

Traditionally the Canvas API allows for only one path to be created and drawn on the canvas. Once this is done and a new path is created, the first path is lost. Path2D objects allows you to declare and retain your paths which can then be reused later.

Path2D is defined in the WhatWG Living Standard Specification. As of December 2017, Path2D is still considered experimental technology according to the MDN Docs.

References

44 questions
0
votes
1 answer

How to animate Path2D objects on canvas

On my canvas I have 2 types of circles : those I created directly from the context (= decorativeStars): drawDecorativeStar = (decorativeStar) => { this.ctx.beginPath(); this.ctx.arc(decorativeStar.x, decorativeStar.y,…
0
votes
1 answer

How to draw SVG path points in Java using Path2D (or any Shape drawer)?

I've been looking for a way to take the points from a SVG and apply that in a Path2D painter. The parsing task is not my point here, the problem is understand how the points works in a canvas and how to apply it to a Path2D. For example, consider I…
Lucas Sousa
  • 192
  • 3
  • 14
0
votes
2 answers

Path2D -- .contain() not working

I am trying to see if a point is contained within a polygon using Path2D. The last line, System.out.println(poly.contains(lat1, lon1)), prints "false" even though I know the coordinates(lat1, lon1) are within the polygon sapecified in "testBound".…
javanewbie14
  • 13
  • 1
  • 5
0
votes
1 answer

detecting a click inside a hexagon drawn using canvas?

I'm working on a certain layout where I need to draw a hexagon which needs to be clickable. I'm using the Path2D construct and isPointInPath function. I'm constructing an animation where a number of hexagons is created and then each moved to a…
Ali Obaji
  • 13
  • 7
0
votes
1 answer

Keep the same distance between 2 Path2D onMouseDragged

I have let's say two Path2D, one contains the other. When I move a point from first shape, the second shape move the same, but because of the angle changing, the distance between shapes changes too (and the final result...). I have this so far, with…
remux
  • 13
  • 6
0
votes
1 answer

Detecting Coordinates Using Path 2d

I am trying to use the contains method provided to do a detection of the coordinates. As researched, the codes I use seem to work fine for others. But in this case, I am unable to get a positive return from my boolean despite it being within the…
Cosq
  • 155
  • 1
  • 2
  • 12
0
votes
2 answers

Trouble with getting Path2D.Double to change with .transform

My program is supposed to allow users to input the first six numbers of a matrix into text fields and then hit an apply button, changing the Path2D using the .transform method with the arguments being the six inputted numbers. My problem is that…
user2872777
  • 99
  • 2
  • 11
0
votes
1 answer

Java custom Path2D

I have created a custom Path2D class to draw an H-shaped "calliper" on screen, for a project I am doing. I want to drag and eventually resize the calliper on screen. I have managed to get the Path2D set up so I can draw the calliper, and the code…
Sam
  • 37
  • 1
  • 3
  • 8
0
votes
0 answers

Intersect an object with a curve

I created a curve with Path2D, and now i want to detect when an object intersect with the curve, not the rectangle that contains the curve. When i draw the curve, the line is contained within a rectangle, but I want to access the precise coordinates…
Nawid
  • 11
  • 3
0
votes
0 answers

Java Path2D.Double, Append But No Subtract

I have looked into using the EVEN-ODD Winding rule in order to create holes in an area. The thing is on the forum all I could come up with was a Path2D.Double() appending a hole within itself. I want to create a whole in an already existing Path2D…
StoneAgeCoder
  • 923
  • 1
  • 7
  • 13
0
votes
1 answer

How to draw custom rectangles in java

There is almost a duplicate for what I'm asking: almost duplicate But I want to make the rounded corners at the top. I tried to modify the code looking at the documentation but I'm pretty new to this drawing in Java and I didn't get it to work.…
malmling
  • 2,398
  • 4
  • 19
  • 33
0
votes
1 answer

Creating a Geometric Path from 2D points without a graphics context. Possible in iOS?

I am needing a way to test out some heavy mathematical functionality in my code and have come to the point where I need to verify that such code is working properly. I would like to be able to create a path based on an array of points and use this…
cspam
  • 2,911
  • 2
  • 23
  • 41
0
votes
2 answers

Java Path2D.Double on JPanel are painted with a 'tail'

I have a strange behaviour when drawing a Path2D on a JPanel. Some of the shapes get kind of a tail as you can see on this screenshot: When I change the type to Line2D.Double, it is as I'd expect it: Here's the code that draws the path /…
klib009
  • 263
  • 5
  • 18
-1
votes
2 answers

Java Graphics2D Path2D Simplify or call from separate class

I'm wondering if I can clean up my code somehow using a list or call it from another class because I have a lot of exact Path2D coordinates just cluttering my paintComponent. public void paintComponent(Graphics g) { Graphics2D…
user3394902
  • 11
  • 1
  • 4
1 2
3