Area - get coordinates
I have an area and would like to get the coordinates directly from this area. The path within this area is closed.
This should work with the interface "PathIterator" from java.awt.geom; I never worked with this interface and don't come to a solution.
Do you have a snippet of code or a tutorial showing how to do this?
Thanks!
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
import javax.swing.event.*;
public class IntersectionRx extends JPanel {
Ellipse2D e = new Ellipse2D.Double(140, 140, 100, 75);
Line2D.Double[] lines = getLines(null, 25);
Line2D.Double line = new Line2D.Double(100, 60, 200, 60);
Point2D.Double[] intxnPoints = new Point2D.Double[0];
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.setPaint(Color.red);
g2.draw(e);
g2.setPaint(Color.blue);
for(int j = 0; j < lines.length; j++)
g2.draw(lines[j]);
g2.setPaint(Color.green.darker());
g2.draw(line);
g2.setPaint(Color.magenta);
for(int j = 0; j < intxnPoints.length; j++) {
Point2D.Double p = intxnPoints[j];
g2.fill(new Ellipse2D.Double(p.x-1.5, p.y-1.5, 4, 4));
public void setLine(int dx, int dy) {
double x1 = line.x1 + dx;
double y1 = line.y1 + dy;
double x2 = line.x2 + dx;
double y2 = line.y2 + dy;
line.setLine(x1, y1, x2, y2);
checkForLineIntersection();
repaint();
private void checkForLineIntersection() {
List<Point2D.Double> list = new ArrayList<Point2D.Double>();
for(int j = 0; j < lines.length; j++) {
if(line.intersectsLine(lines[j])) {
list.add(getIntersection(line, lines[j]));
intxnPoints = list.toArray(new Point2D.Double[list.size()]);
private Point2D.Double getIntersection(Line2D.Double line1, Line2D.Double line2) {
double x1 = line1.x1; double y1 = line1.y1;
double x2 = line1.x2; double y2 = line1.y2;
double x3 = line2.x1; double y3 = line2.y1;
double x4 = line2.x2; double y4 = line2.y2;
double dividend = (x4 - x3)*(y1 - y3) - (y4 - y3)*(x1 - x3);
double divisor = (y4 - y3)*(x2 - x1) - (x4 - x3)*(y2 - y1);
double ua = dividend / divisor;
Point2D.Double p = new Point2D.Double();
p.x = x1 + ua * (x2 - x1);
p.y = y1 + ua * (y2 - y1);
//System.out.printf("p = [%5.1f, %5.1f]%n", p.x, p.y);
return p;
private Line2D.Double[] getLines(AffineTransform at, double flatness) {
List<Line2D.Double> list = new ArrayList<Line2D.Double>();
PathIterator pit = e.getPathIterator(at, flatness);
double[] coords = new double[6];
double lastX = 0, lastY = 0;
int count = 0;
while(!pit.isDone()) {
int type = pit.currentSegment(coords);
switch(type) {
case PathIterator.SEG_MOVETO:
lastX = coords[0];
lastY = coords[1];
break;
case PathIterator.SEG_LINETO:
list.add(new Line2D.Double(lastX, lastY, coords[0], coords[1]));
System.out.printf("lines[%d] = [%5.1f, %5.1f, %5.1f, %5.1f]%n",
count++, lastX, lastY, coords[0], coords[1]);
lastX = coords[0];
lastY = coords[1];
pit.next();
return list.toArray(new Line2D.Double[list.size()]);
public static void main(String[] args) {
IntersectionRx test = new IntersectionRx();
LineTransporter controller = new LineTransporter(test);
test.addMouseListener(controller);
test.addMouseMotionListener(controller);
JFrame f = new JFrame("drag green line");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(test);
f.setSize(400,400);
f.setLocation(200,200);
f.setVisible(true);
class LineTransporter extends MouseInputAdapter {
IntersectionRx component;
final int S = 6;
Rectangle feeler = new Rectangle(S,S);
Point start;
boolean dragging = false;
Cursor cursor = Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR);
public LineTransporter(IntersectionRx ir) {
component = ir;
public void mousePressed(MouseEvent e) {
if(component.getCursor() == cursor) {
start = e.getPoint();
dragging = true;
public void mouseReleased(MouseEvent e) {
dragging = false;
public void mouseDragged(MouseEvent e) {
if(dragging) {
Point end = e.getPoint();
int dx = end.x - start.x;
int dy = end.y - start.y;
start = end;
component.setLine(dx, dy);
public void mouseMoved(MouseEvent e) {
feeler.setLocation(e.getX()-S/2, e.getY()-S/2);
boolean hovering = false;
Line2D.Double line = component.line;
if(line.intersects(feeler)) {
hovering = true;
if(component.getCursor() == Cursor.getDefaultCursor())
component.setCursor(cursor);
if(!hovering && component.getCursor() == cursor)
component.setCursor(Cursor.getDefaultCursor());
}
Similar Messages
-
how can i calculate the area of geometric figure, for example
i have this 5 points (with coordinates):
1 (30,20)
2 (50,40)
3 (40,60)
4 (30,60)
5 (20,40)
my table is: point_number | X-coord | Y-coord
mathematical formula for AREA from coordinates is:
abs[(x1-x3)*y2+(x2-x4)*y3+(x3-x5)*y4+(x4-x1)*y5+(x5-x2)*y1]/2
but I dont know how can i doo that?
thanx,
Mateo Gasparovic (CROATIA)Mateo, here is how you can do in pl/sql.
SQL> drop table coordinates
2 /
Table dropped.
SQL>
SQL> create table coordinates
2 (point_number number
3 ,x number
4 ,y number)
5 /
Table created.
SQL>
SQL> insert into coordinates values(1,30,20)
2 /
1 row created.
SQL> insert into coordinates values(2,50,40)
2 /
1 row created.
SQL> insert into coordinates values(3,40,60)
2 /
1 row created.
SQL> insert into coordinates values(4,30,60)
2 /
1 row created.
SQL> insert into coordinates values(5,20,40)
2 /
1 row created.
SQL>
SQL> set serveroutput on
SQL>
SQL> declare
2 /*x,y coordinate constants*/
3 x_coord char := 'X';
4 y_coord char := 'Y';
5
6 --resultant area variable
7 area number;
8
9 --local function to get the point value for a x,y coordinate
10 function get_xy(point number, cord char) return number is
11 ret_val number;
12 begin
13 for i in (select x ,y from coordinates where point_number = point)
14 loop
15 if cord = x_coord then
16 ret_val := i.x;
17 else
18 ret_val := i.y;
19 end if;
20 return ret_val;
21 end loop;
22 end get_xy;
23
24 --wrapper function to get x coordinate value
25 function x(point number) return number is
26 begin
27 return (get_xy(point, x_coord));
28 end x;
29
30 --wrapper function to get y coordinate value
31 function y(point number) return number is
32 begin
33 return (get_xy(point, y_coord));
34 end y;
35 begin
36 area := abs((x(1)-x(3))*y(2)+(x(2)-x(4))*y(3)+(x(3)-x(5))*y(4)+(x(4)-x(1))*y(5)+(x(5)-x(2))*y(1))/2;
37 dbms_output.put_line('geometric area '|| area);
38 end ;
39 /
geometric area 700
PL/SQL procedure successfully completed.
SQL>here is the code
drop table coordinates
create table coordinates
(point_number number
,x number
,y number)
insert into coordinates values(1,30,20)
insert into coordinates values(2,50,40)
insert into coordinates values(3,40,60)
insert into coordinates values(4,30,60)
insert into coordinates values(5,20,40)
set serveroutput on
declare
/*x,y coordinate constants*/
x_coord char := 'X';
y_coord char := 'Y';
--resultant area variable
area number;
--local function to get the point value for a x,y coordinate
function get_xy(point number, cord char) return number is
ret_val number;
begin
for i in (select x ,y from coordinates where point_number = point)
loop
if cord = x_coord then
ret_val := i.x;
else
ret_val := i.y;
end if;
return ret_val;
end loop;
end get_xy;
--wrapper function to get x coordinate value
function x(point number) return number is
begin
return (get_xy(point, x_coord));
end x;
--wrapper function to get y coordinate value
function y(point number) return number is
begin
return (get_xy(point, y_coord));
end y;
begin
area := abs((x(1)-x(3))*y(2)+(x(2)-x(4))*y(3)+(x(3)-x(5))*y(4)+(x(4)-x(1))*y(5)+(x(5)-x(2))*y(1))/2;
dbms_output.put_line('geometric area '|| area);
end ;
/ -
Not all fields are getting updated in transformation
Dear all,
Please help me in the following issue:
I have the following scenario:
DSO1 and CUBE1. From DSO1 to CUBE1 I have transformation. Fields are mapped one to one.
Some of the fields are getting updated in transformation (22 fields) and some of them are not updated in transformation. (2 - storage location and steel grade).
The fields exist in DSO 1 but don't go into cube.
I did the following:
1. deleted transformation and dtp, recreate = > not working
2. copied the cube, and create new transformation and DTP...not working.
Any help would be appreciated
Thank you
RamonaHi Ramona,
Storage location (standard infoobject 0STOR_LOC) has plant as compunding object, check whether this is the issue ? (may be check with Steel grade infoobject also).
Else, do some RSRV checks on the DSO and Infoobject, if it doesn't bring up any issue, raise a message with SAP.
Check your BW Support Pack level , is it the latest ? Give more details about the scenario ?
Cheers,
CK -
I have been using one apple ID for my family as it makes it easier to manage itunes purchases/rentals on all of our devices. Now that my kids are getting old and my wife has recently purchased an Iphone, I can see that I need to change my strategy. I plan to add a few more iphones to the family very soon. What is your recommendation to manage all of our devices (iphones, itouch, apple tv) for my family? Can I continue to function with one apple ID or is it time to take the leep into attempting to manage multi-apple ID's?
There's a few ways of managing multiple devices on a single computer (and keeping seperate content on each). The following document is worth checking through:
How to use multiple iPods, iPads, or iPhones with one computer -
SAP Standard Jobs are getting canceled
Hi Basis Gurus,
In our Quality BW 3.5 system the SAP Standard jobs are getting canceled.
The jobs are as follows
SAP_APPLICATION_STAT_COLLECTOR
SAP_CCMS_CPH_HRCOLL
SAP_CCMS_MONI_BATCH_DP
SAP_COLLECTOR_FOR_JOBSTATISTIC
SAP_COLLECTOR_FOR_NONE_R3_STAT
SAP_COLLECTOR_FOR_PERFMONITOR
SAPCONNECT ALL SEND
SAP_REORG_ABAPDUMPS
SAP_REORG_SPOOL
SAP_RSICFDLT
In SM37 when i click on the job log for the above mentioned jobs the system is promting a message saying as "Error reading job log"
Please let me know how can troubleshoot it and resolve this issue.
Our is qulaity BW 3.5 system
Solaris OS
Oracle Database
Please help me.
Regards,
Anil.Hi ,
For log display reason, try the note suggested. Jobs cancel reason may be due to that the user who schedule that job are locked or not exist on that client. Or other reason will be clear only after log display.
Ankit -
Past due PurRqs are getting deleted in APO but not getting deletd in R3
Hi folks,
We have a daily job, which runs at 18:00 hrs in the evening everyday in the APO Production System.The job is to delete all past due Purchase Requisitions for last 2 years (job & variant details are mentioned below) All the past due PurRqs are getting deleted from APO, which we have cross-cheked in RRP3 view many times.
However the same is not getting deleted in R3 systems. The planner/end- user is getting confused & hassled by this list of old PurRqs which is visible in R3 through MD04 t-code.
Please suggest remedial/corrective actions to get this issue sorted.
The job details for the deletion of past purchase requisitions.
The job is run with the following variant details:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ABAP Program name :/SAPAPO/RLCDELETE
VARIANT Details
Select Object-> By Categories ->Category = AG (PurRqs in R3)
Manual Selection-> Version =000; Product = (blank); Location = List ofall locations;
Fixed Order (ticked)
Period = 14.03.2009 to 14.03.2011 {All PurRqs in these period shouldget deleted in APO as well as R3}
Settings-> Delete Transaction Data ->In R3 & APO (ticked)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Past due PurRqs are not getting deleted in R3 systems. The planner/end-user is getting confused & hassled resulting in loss of productive time & generation of erroneous planning which is negatively impacting Business.
Pls suggest some remedy for this.
MMTIA
Kumar
Edited by: Blue Lotus on Mar 14, 2011 5:51 PMDo you run the CCR on a daily basis. If so do you see the "reqs missing in R/3" in the CCR ?
Also what is your transfer setting ? Meaning the transfer from APO to R/3 configuration - is it immediate or change pointer based ? check that also
Thanks
Aparna -
Some fields are getting hidden in contract..
Hi All,
I have a problem while creating contract in ME31K.
Start of Validity period validity period end fields are getting hidden in ME31k.
Field selection group for the contract document type is WKK and these fields in this group are 'required entries'.
I don't understand how come these fields are disapearing in contract..
Can anybody please figure out the problem...
Thanks in advance
RajuHi,
In ME31K, these date fields will be usually not showed on the initial screen. While creating contract, after entering vendor, agreement type, agreement date, organizational data, we will be taken to the next screen where in we need to fill validity start date and end date.
In ME33K we can see this information under Header - > Details menu path.
If these dates are not available in the details tab, you might need to create a transaction variant from "SHD0" transaction. Please check under details tab and if not available create try to create a transaction varaint.
Hope this helps you !!!
Regards,
Ganga -
Not all songs are getting synced into my iPhone
Why is this? I have no clue. Only ~200 of my ~500 songs are getting uploaded.
Also, what's the best way to store songs in my computer, such that it will not get duplicated on my iTunes and/or iPhone?
Currently, I store the song as "Led Zeppelin - Stairway to Heaven" on my computer.Are you manually managing music and videos, or syncing?
If syncing, do you have all songs and playlists or selected playlists selected under the Music tab for your iPhone sync preferences?
Under the Summary tab for your iPhone sync preferences, do you have Sync only checked songs and videos selected?
If so, are all songs selected or checked in your iTunes music library?
Also, what's the best way to store songs in my computer, such that it will not get duplicated on my iTunes and/or iPhone?
When importing songs from another source besides the iTunes Store or when imported from a music CD, there is an iTunes option to copy files to iTunes Music Folder when adding to library, which is available at iTunes preferences under the Advanced tab below General. -
Line Items are getting rejected in Sales Orders
Hi,
I am creating sales orders using ORDERS Message type and for this I am using the Standard SAP Inbound Function Module to create sales orders.
Idocs are getting processed successfully and sales orders are getting created, but line items in the sales order are getting rejected and hey are getting rejected with reason for rejection to be <b> No Availability Lost</b>.
So, I would like to know if this is a problem with the data furnished in the Idoc or else any custom setting have to be maintained or not?
RaghuramThe reason why they are failing is because in the user exit as per the logic present here whenever a EDI Order with customer Purchaser Order Type DFUE is to be processed ABGRU (Reason for Rejection) has been flagged equal to 01 and hence order item lines are having rejection reason.
-
All graphics / vector in Save for Web are getting blurry / unsharp from Illustrator
All graphics / vector in Save for Web are getting blurry / unsharp from Illustrator. Same problem with save for web in Photoshop. Frustrating to be working as a designer and not be able to create sharp logos for mail sign, word templates, PPT templates etc etc. I purchased this Adobe Creative Cloud package in Sept, and are working on my Mac HD, OSX, Vers 10.9.4. I have been using the same programs on a PC for years and never had this same problem. Its frustrating!! What to do??
gif, jpg and png are pixel formats, so please clarify what the problem is supposed to be.
Screenshots or posted files might help. -
Credit card Orders are getting blocked with credit check
Hi All
In our system, If customer's credit exposure is greater then 100 % then all the credit card orders are getting blocked with credit check even though it has valid authorization. Is this sap standard behaviour?....is there any setting that will always exclude credit card orders when it has valid authorization
Thanks in advance for looking into thisHi,
In OVA8- under document controlling- check the existing routinue 1 for orders etc., else modify as per your requirement
Thanks
Chidamabram -
My husband and I share the same itunes account, but we are getting each other's photos on our phones. What setting will disable this?
turn off photo stream My Photo Stream FAQ - Apple Support
-
Hi. I have shared an Apple ID with my children for some time. As they are getting older they do not wnat me seeing all their messages, photos etc so want their own accounts. How can they access their purchased music and apps on the new account please?
Yes.
On their iOS devices, under Settings>iTunes & App Store, they should use your Apple ID. When they log into iCloud, iMessage and Facetime, they should use their personal Apple IDs. -
I have been sharing my iTunes account with my kids...now they are getting older and want to have their own accounts, how do I share the songs I purchased for them on my account with them on their new accounts? Is there a way to transer from my main account their new accounts? And can I share music from my account with them?
You can't currently transfer content from one account to another account. As long as the tracks are on the computer's iTunes that they use/sync to, and your account is authorised on that iTunes, then they should be able to continue to use them.
-
I have the new iOS 7 and am getting texts from another family members phone and they are getting mine how do I disable this without changing accounts
Welcome to the Apple Community.
You could simply set each device to only use a single telephone number (settings > messages > send & receive, but this isn't really an ideal solution since the other person can always change their settings and see your messages and send messages that appear as if they are from you. There is only one real solution and that's to have your own accounts.
Maybe you are looking for
-
Delete Dataset File not working
Hi All, I am trying to delete file from application server (AL11) directory after processing using DELETE DATASET FILE is not working , after processing also file still exists. My code is like this, *& Form backup_file The file has been
-
Telstra pre-paid mobile broadband
Has anyboby managed to setup up a Telstra Pre-Paid Mobile Broadband Turbo on OSX Lion 10.7.1. The dongle works fine on my WIndows machine so no issues with activation of the sim or account balancwe etc. I've downloaded and installed the latest versio
-
Next version release date?
Hi, When will the next Teaming version (3.0 ?) available? If there any release date known? Or announced? THX Andre
-
Scratch Disk Full error for PS7 installation in Windows 7
Can anyone from Adobe tech support tell me how to install my own copy of PS7 on my new Windows 7 computer without having the Scratch Disk Full error show up? I am comfortable around my computer but am certainly not a tech wizard and it would be help
-
What is credential file ? How to get this file ?
Dear all, I am config ADS and need a credential file: *.pfx What is it, how can I get this file? Thanks a lot.